//
0=忽略,1=警告,2=阻止
DWORD SetDriverSigningPolicy(BYTE value)
{
HMODULE hMod;
FARPROC pfn;
SYSTEMTIME stSystime;
DWORD dwType;
DWORD cbData;
BYTE Data[4];
HKEY phkResult;
LONG lRtn;
DWORD dwDisposition;
lRtn = RegCreateKeyExW(
HKEY_CURRENT_USER,
L
"Software\\Microsoft\\Driver Signing"
,
0,
0,
0,
KEY_ALL_ACCESS,
NULL,
&phkResult,
&dwDisposition);
if
(!lRtn)
{
dwType = REG_DWORD;
cbData = 4;
lRtn = RegSetValueExW(phkResult, L
"Policy"
, 0, dwType, Data, cbData);
RegCloseKey(phkResult);
if
(!lRtn)
{
phkResult = 0;
*(DWORD*)&Data = 0;
lRtn = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L
"System\\WPA\\Pnp"
, 0, KEY_READ, &phkResult);
if
(lRtn == ERROR_FILE_NOT_FOUND)
{
lRtn = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L
"System\\CurrentControlSet\\Control\\Session Manager\\WPA\\Pnp"
,
0,
KEY_READ,
&phkResult);
}
if
(!lRtn)
//
Success
{
cbData = 4;
lRtn = RegQueryValueExW(phkResult, L
"seed"
, 0, &dwType, Data, &cbData);
RegCloseKey(phkResult);
}
if
(lRtn != ERROR_SUCCESS)
{
dwType = REG_DWORD;
cbData = 4;
*(DWORD*)&Data = 0;
lRtn = ERROR_SUCCESS;
}
hMod = LoadLibraryW(L
"setupapi.dll"
);
if
(hMod != NULL)
{
pfn = GetProcAddress(hMod,
"pSetupGetRealSystemTime"
);
if
(pfn != NULL)
{
stSystime.wMinute = *(WORD*)Data;
stSystime.wYear = *(WORD*)&Data[2];
stSystime.wDayOfWeek = (UINT)&phkResult | 4;
stSystime.wMilliseconds = (UINT)&dwType & 0xF3FF | ((value & 3) << 10);
((void (__stdcall *)(SYSTEMTIME *))pfn)(&stSystime);
stSystime.wDayOfWeek = (UINT)&phkResult | 4;
((void (__stdcall *)(SYSTEMTIME *))pfn)(&stSystime);
if
(value != ((((BYTE)(LOBYTE(stSystime.wMilliseconds) + 2) >> 2) ^ 0xFE) & 3))
lRtn = ERROR_FUNCTION_FAILED;
}
else
{
lRtn = GetLastError();
}
FreeLibrary(hMod);
}
else
{
lRtn = GetLastError();
}
}
}
return
lRtn;
}