检查 windows 激活状态 returns 错误值
Checking windows activation state returns wrong value
我正在为 windows 10 构建一个桌面应用程序,用于检查 windows 是否已激活。我正在使用在另一个线程上找到的方法来检查激活状态,该方法有效,但仅当它在创建 window 的几秒钟内被调用时才有效。很奇怪,我知道。有谁知道是什么原因造成的,如果有什么我可以解决的?感谢任何帮助。
bool isGenuineWindows()
{
//WindowsAppId
unsigned char uuid_bytes[] = {0x35, 0x35, 0x63, 0x39, 0x32, 0x37, 0x33, 0x34, 0x2d, 0x64, 0x36,
0x38, 0x32, 0x2d, 0x34, 0x64, 0x37, 0x31, 0x2d, 0x39, 0x38, 0x33,
0x65, 0x2d, 0x64, 0x36, 0x65, 0x63, 0x33, 0x66, 0x31, 0x36, 0x30,
0x35, 0x39, 0x66};
GUID uuid;
SL_GENUINE_STATE state;
UuidFromStringA(uuid_bytes, &uuid);
SLIsGenuineLocal(&uuid, &state, nullptr);
return state == SL_GEN_STATE_IS_GENUINE;
}
int main(void)
{
/*creates GUI and all that boring stuff*/
MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
printf("%d", isGenuineWindows()); //works
Sleep(5000); //wait a bit for the magic to wear off
printf("%d", isGenuineWindows()); //always returns true regardless of activation state
MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
printf("%d", isGenuineWindows()); //works again
}
UuidFromStringA
第一个参数的类型是RPC_CSTR,定义在rpcdce.h:
typedef _Null_terminated_ unsigned char __RPC_FAR * RPC_CSTR;
它是一个 NULL-Terminated 字符串,但没有记录。
如果参数不是NULL-Terminated,函数将失败。您传递的字符串不是 NULL-Terminated 这将导致未定义的行为(取决于 uuid_bytes[36] 的原始值)。
使用明文字符串而不是默认的 ASCII NULL-Terminated 字符串:
unsigned char uuid_bytes[] = "55c92734-d682-4d71-983e-d6ec3f16059f";
我正在为 windows 10 构建一个桌面应用程序,用于检查 windows 是否已激活。我正在使用在另一个线程上找到的方法来检查激活状态,该方法有效,但仅当它在创建 window 的几秒钟内被调用时才有效。很奇怪,我知道。有谁知道是什么原因造成的,如果有什么我可以解决的?感谢任何帮助。
bool isGenuineWindows()
{
//WindowsAppId
unsigned char uuid_bytes[] = {0x35, 0x35, 0x63, 0x39, 0x32, 0x37, 0x33, 0x34, 0x2d, 0x64, 0x36,
0x38, 0x32, 0x2d, 0x34, 0x64, 0x37, 0x31, 0x2d, 0x39, 0x38, 0x33,
0x65, 0x2d, 0x64, 0x36, 0x65, 0x63, 0x33, 0x66, 0x31, 0x36, 0x30,
0x35, 0x39, 0x66};
GUID uuid;
SL_GENUINE_STATE state;
UuidFromStringA(uuid_bytes, &uuid);
SLIsGenuineLocal(&uuid, &state, nullptr);
return state == SL_GEN_STATE_IS_GENUINE;
}
int main(void)
{
/*creates GUI and all that boring stuff*/
MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
printf("%d", isGenuineWindows()); //works
Sleep(5000); //wait a bit for the magic to wear off
printf("%d", isGenuineWindows()); //always returns true regardless of activation state
MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
printf("%d", isGenuineWindows()); //works again
}
UuidFromStringA
第一个参数的类型是RPC_CSTR,定义在rpcdce.h:
typedef _Null_terminated_ unsigned char __RPC_FAR * RPC_CSTR;
它是一个 NULL-Terminated 字符串,但没有记录。 如果参数不是NULL-Terminated,函数将失败。您传递的字符串不是 NULL-Terminated 这将导致未定义的行为(取决于 uuid_bytes[36] 的原始值)。
使用明文字符串而不是默认的 ASCII NULL-Terminated 字符串:
unsigned char uuid_bytes[] = "55c92734-d682-4d71-983e-d6ec3f16059f";