使用這個鏈接 :)
http://blogs.technet.com/b/fdcc/archive/2010/01/15/updated-lgpo-utility-sources.aspx
您可以使用此項目在本地系統上修改GPO。 不改變直接註冊!!!!
HRESULT hr;
IGroupPolicyObject* pLGPO;
HKEY machine_key, dsrkey;
const IID my_IID_IGroupPolicyObject =
{ 0xea502723, 0xa23d, 0x11d1, { 0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3 } };
const IID my_CLSID_GroupPolicyObject =
{ 0xea502722, 0xa23d, 0x11d1, { 0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3 } };
GUID ext_guid = REGISTRY_EXTENSION_GUID;
// This next one can be any GUID you want
GUID snap_guid = { 0x3d271cfc, 0x2bc6, 0x4ac2, { 0xb6, 0x33, 0x3b, 0xdf, 0xf5, 0xbd, 0xab, 0x2a } };
// Create an instance of the IGroupPolicyObject class
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CoCreateInstance(my_CLSID_GroupPolicyObject, NULL, CLSCTX_INPROC_SERVER,
my_IID_IGroupPolicyObject, (LPVOID*)&pLGPO);
// We need the machine LGPO (if C++, no need to go through the lpVtbl table)
hr = pLGPO->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY);
hr = pLGPO->GetRegistryKey(GPO_SECTION_MACHINE, &machine_key);
//hr = pLGPO->GetRegistryKey(GPO_SECTION_USER, &machine_key);
// The disable System Restore is a DWORD value of Policies\Microsoft\Windows\DeviceInstall\Settings
LSTATUS sdf = RegCreateKeyEx(machine_key, L"Software\\Policies\\Microsoft\\Windows\\DeviceInstall\\Settings",
0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, &dsrkey, NULL);
// Create the value
LSTATUS ds = RegSetKeyValue(dsrkey, NULL, KeyValue, REG_DWORD, &KeyData, sizeof(KeyData));
RegCloseKey(dsrkey);
// Apply policy and free resources
//pLGPO->Save(TRUE, TRUE, &ext_guid, &snap_guid);
GUID RegistryId = REGISTRY_EXTENSION_GUID;
GUID ThisAdminToolGuid =
/*{ CLSID_PolicySnapinUser/* */
{
0x0F6B957E,
0x509E,
0x11D1,
{ 0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3 }
};
LSTATUS rStatus = RegCloseKey(machine_key);
//
// Write the GPO back to the directory
//
hr = pLGPO->Save(
FALSE,
TRUE,
&RegistryId,
&ThisAdminToolGuid);
RegCloseKey(machine_key);
pLGPO->Release();
你知道我該如何在純C中使用這個庫嗎?因爲我的項目是在minGW下用'./configure && make && make install'編譯的。謝謝 – 2013-12-01 21:56:49
我在此C解決方案的基礎上,基於.NET庫:http://pete.akeo.ie/2011/03/porgramatically-setting-and-applying.html 我的.NET解決方案的源代碼可以在鏈接上面,以防萬一。 – 2013-12-03 09:28:51