/// <summary> /// Constructor. /// </summary> /// <param name="remoteMachineName">Target machine name to operate group policy</param> /// <exception cref="System.Runtime.InteropServices.COMException">Throw when com execution throws exceptions</exception> public GroupPolicyObjectHandler(String remoteMachineName) { groupPolicyObject = new GroupPolicyObject(); iGroupPolicyObject = (IGroupPolicyObject)groupPolicyObject; try { if (String.IsNullOrEmpty(remoteMachineName)) { iGroupPolicyObject.OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY); } else { iGroupPolicyObject.OpenRemoteMachineGPO(remoteMachineName, GPO_OPEN_LOAD_REGISTRY); } } catch (COMException e) { throw e; } }
private void DeleteUserDelegateSettings() { IGroupPolicyObject gPClass = (IGroupPolicyObject)(new GPClass()); gPClass.OpenLocalMachineGPO(1); gPClass.GetRegistryKey(2); RegistryKey currentUser = Registry.CurrentUser; string str = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy Objects"; RegistryKey registryKey = currentUser.OpenSubKey(str, true); string[] subKeyNames = registryKey.GetSubKeyNames(); for (int i = 0; i < (int)subKeyNames.Length; i++) { string str1 = subKeyNames[i]; if (str1.EndsWith("Machine", StringComparison.OrdinalIgnoreCase)) { string str2 = string.Concat(str, "\\", str1, "\\Software\\Policies\\Microsoft\\Windows"); this.DeleteDelegateSettings("wsman", Registry.CurrentUser, str2, gPClass); } } }
private void DeleteUserDelegateSettings() { System.IntPtr KeyHandle = System.IntPtr.Zero; IGroupPolicyObject GPO = (IGroupPolicyObject) new GPClass(); GPO.OpenLocalMachineGPO(1); KeyHandle = GPO.GetRegistryKey(2); RegistryKey rootKey = Registry.CurrentUser; string GPOpath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy Objects"; RegistryKey GPOKey = rootKey.OpenSubKey(GPOpath, true); foreach (string keyname in GPOKey.GetSubKeyNames()) { if (keyname.EndsWith("Machine", StringComparison.OrdinalIgnoreCase)) { string key = GPOpath + "\\" + keyname + "\\" + @"Software\Policies\Microsoft\Windows"; DeleteDelegateSettings(applicationname, Registry.CurrentUser, key, GPO); } } KeyHandle = System.IntPtr.Zero; }
/// <summary> /// </summary> private void UpdateCurrentUserRegistrySettings() { System.IntPtr KeyHandle = System.IntPtr.Zero; IGroupPolicyObject GPO = (IGroupPolicyObject) new GPClass(); GPO.OpenLocalMachineGPO(1); KeyHandle = GPO.GetRegistryKey(2); RegistryKey rootKey = Registry.CurrentUser; const string GPOpath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy Objects"; RegistryKey GPOKey = rootKey.OpenSubKey(GPOpath, true); foreach (string keyname in GPOKey.GetSubKeyNames()) { if (keyname.EndsWith("Machine", StringComparison.OrdinalIgnoreCase)) { string key = GPOpath + "\\" + keyname + "\\" + @"Software\Policies\Microsoft\Windows"; UpdateGPORegistrySettings(applicationname, this.delegatecomputer, Registry.CurrentUser, key); } } // saving gpo settings GPO.Save(true, true, new Guid("35378EAC-683F-11D2-A89A-00C04FBBCFA2"), new Guid("7A9206BD-33AF-47af-B832-D4128730E990")); }
private void UpdateCurrentUserRegistrySettings() { IGroupPolicyObject gPClass = (IGroupPolicyObject)(new GPClass()); gPClass.OpenLocalMachineGPO(1); gPClass.GetRegistryKey(2); RegistryKey currentUser = Registry.CurrentUser; string str = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy Objects"; RegistryKey registryKey = currentUser.OpenSubKey(str, true); string[] subKeyNames = registryKey.GetSubKeyNames(); for (int i = 0; i < (int)subKeyNames.Length; i++) { string str1 = subKeyNames[i]; if (str1.EndsWith("Machine", StringComparison.OrdinalIgnoreCase)) { string str2 = string.Concat(str, "\\", str1, "\\Software\\Policies\\Microsoft\\Windows"); this.UpdateGPORegistrySettings("wsman", this.delegatecomputer, Registry.CurrentUser, str2); } } gPClass.Save(true, true, new Guid("35378EAC-683F-11D2-A89A-00C04FBBCFA2"), new Guid("7A9206BD-33AF-47af-B832-D4128730E990")); }