Improve: Change registry/mutex name of client program

This commit is contained in:
yuanyuanxiang
2025-12-22 10:52:38 +01:00
parent d580d282d8
commit 3aedb38217
4 changed files with 64 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
#include "common/commands.h"
#define YAMA_PATH "Software\\YAMA"
#define CLIENT_PATH "Software\\ServerD11"
#define CLIENT_PATH GetRegistryName()
#define NO_CURRENTKEY 1
@@ -12,6 +12,41 @@
#include <sddl.h>
#pragma comment(lib, "wtsapi32.lib")
inline std::string GetExeDir()
{
char path[MAX_PATH];
GetModuleFileNameA(nullptr, path, MAX_PATH);
char* lastSlash = strrchr(path, '\\');
if (lastSlash) *lastSlash = '\0';
CharLowerA(path);
return path;
}
inline std::string GetExeHashStr()
{
char path[MAX_PATH];
GetModuleFileNameA(nullptr, path, MAX_PATH);
CharLowerA(path);
ULONGLONG hash = 14695981039346656037ULL;
for (const char* p = path; *p; p++)
{
hash ^= (unsigned char)*p;
hash *= 1099511628211ULL;
}
char result[17];
sprintf_s(result, "%016llX", hash);
return result;
}
static inline std::string GetRegistryName() {
static auto name = "Software\\" + GetExeHashStr();
return name;
}
// 获取当前会话用户的注册表根键
// SYSTEM 进程无法使用 HKEY_CURRENT_USER需要通过 HKEY_USERS\<SID> 访问
// 返回的 HKEY 需要调用者在使用完毕后调用 RegCloseKey 关闭
@@ -159,6 +194,10 @@ public:
{
m_hRootKey = GetCurrentUserRegistryKey();
m_SubKeyPath = path;
if (path != YAMA_PATH) {
static std::string workSpace = GetExeDir();
SetStr("settings", "work_space", workSpace);
}
}
// 写入整数,实际写为字符串
@@ -233,6 +272,10 @@ public:
{
m_hRootKey = GetCurrentUserRegistryKey();
m_SubKeyPath = path;
if (path != YAMA_PATH) {
static std::string workSpace = GetExeDir();
SetStr("settings", "work_space", workSpace);
}
}
// 写入整数(写为二进制)