使用SetupAPI,您也可以更改SDS。這並不直接回答你的問題,但它確實解決了不安全描述符的問題。
static GUID MY_GUID = { 0x91A3EB99, 0x5FB7, 0x4CA4, { 0x83, 0xC9, 0x8E, 0x39, 0xC1, 0x39, 0xEF, 0xE8 } };
SetClassSDS(&MY_GUID);
如果你願意,你也可以通過在你SetupDiClassGuidsFromNameEx檢索的GUID:
SetClassSDS(&cls);
這是上面使用我的函數(一定要使用你想要的ACL):
void SetClassSDS(GUID* guid)
{
wprintf(L"\tGUID: {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n",
guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2],
guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
const int strSize = 256;
// This discretionary ACL:
// * Deny access to Built-in Guests
// * Deny access to Anonymous Logon
// * Allow read/write/execute to Authenticated Users
// * Allow full control to Administrators
WCHAR newStr[strSize] = L"D:(D;OICI;GA;;;BG)(D;OICI;GA;;;AN)(A;OICI;GRGWGX;;;AU)(A;OICI;GA;;;BA)";
PBYTE str = new BYTE[strSize];
DEVPROPTYPE type;
DWORD reqSize = 0;
if (SetupDiGetClassProperty(guid, &DEVPKEY_DeviceClass_SecuritySDS, &type, str, strSize, &reqSize, DICLASSPROP_INSTALLER))
{
wprintf(L"\tCurrent SDS: %s\n", str);
wprintf(L"\tDesired SDS: %s\n", newStr);
if (SetupDiSetClassProperty(guid, &DEVPKEY_DeviceClass_SecuritySDS, type,
(BYTE*)newStr, sizeof(newStr), DICLASSPROP_INSTALLER))
{
wprintf(L"\n\tSetupDiSetClassProperty succeeded\n\n");
}
else
{
wprintf(L"\tSetupDiSetClassProperty - Error code: 0x%X\n\n", GetLastError());
}
}
else
{
wprintf(L"\tSetupDiGetClassProperty - Error code: 0x%X\n\n", GetLastError());
if (reqSize > strSize)
{
wprintf(L"\tSecurity string too long\n");
}
}
wprintf(L"\n");
delete [] str;
}
您將需要以下包括:
#include <initguid.h>
#include <devguid.h>
#include <devpkey.h>
#include <devpropdef.h>
#include <setupapi.h>
您需要鏈接到該庫:
Setupapi.lib