相关文章推荐
有胆有识的大熊猫  ·  Java ...·  1 年前    · 
长情的单车  ·  kendo ui ...·  1 年前    · 
爱听歌的土豆  ·  C++ ...·  1 年前    · 
12 IGroupPolicyObject* pLGPO; 13 HKEY machine_key, dsrkey; 14 // MSVC is finicky about these ones => redefine them 15 const IID my_IID_IGroupPolicyObject = 16 { 0xea502723 , 0xa23d , 0x11d1 , { 0xa7 , 0xd3 , 0x0 , 0x0 , 0xf8 , 0x75 , 0x71 , 0xe3 } }; 17 const IID my_CLSID_GroupPolicyObject = 18 { 0xea502722 , 0xa23d , 0x11d1 , { 0xa7 , 0xd3 , 0x0 , 0x0 , 0xf8 , 0x75 , 0x71 , 0xe3 } }; 19 GUID ext_guid = REGISTRY_EXTENSION_GUID; 20 // This next one can be any GUID you want 21 GUID snap_guid = { 0x3d271cfc , 0x2bc6 , 0x4ac2 , { 0xb6 , 0x33 , 0x3b , 0xdf , 0xf5 , 0xbd , 0xab , 0x2a } }; 23 // Create an instance of the IGroupPolicyObject class 24 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 25 if (FAILED(hr)) 26 { 27 std::ostringstream errorStream; 28 errorStream << " Failed to initialize COM library. Error code = 0x " << std::hex << hr << std::endl; 29 std::cout << errorStream.str() << std::endl; 30 return 0 ; 31 } 33 hr = CoCreateInstance(my_CLSID_GroupPolicyObject, NULL, CLSCTX_INPROC_SERVER, 34 my_IID_IGroupPolicyObject, (LPVOID*)& pLGPO); 36 // We need the machine LGPO (if C++, no need to go through the lpVtbl table) 37 pLGPO-> OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY); 38 pLGPO->GetRegistryKey(GPO_SECTION_MACHINE, & machine_key); 40 // The disable System Restore is a DWORD value of Policies\Microsoft\Windows\DeviceInstall\Settings 41 RegCreateKeyEx(machine_key, " SOFTWARE\\Policies\\Microsoft\\Windows\\DeviceInstall\\Restrictions " , 42 0 , NULL, 0 , KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, & dsrkey, NULL); 44 // Create the value 45 val = 1 ; 46 RegSetKeyValue(dsrkey, NULL, " DenyRemovableDevices " , REG_DWORD, &val, sizeof (val)); 47 RegCloseKey(dsrkey); 49 // Apply policy and free resources 50 pLGPO->Save(TRUE, TRUE, &ext_guid, & snap_guid); 51 RegCloseKey(machine_key); 52 pLGPO-> Release(); 53 return 0 ;

rereferences:

http://pete.akeo.ie/2011/03/porgramatically-setting-and-applying.html

http://www.nirsoft.net/utils/reg_file_from_application.html

http://blog.sina.com.cn/s/blog_4e0987310101irm8.html