Exemple #1
0
            /// <summary>
            /// Retrieves a handle to the root of the registry key for the machine section.
            /// </summary>
            /// <returns>A handle to the root of the registry key for the specified GPO computer section</returns>
            /// <exception cref="System.Runtime.InteropServices.COMException">Throw when com execution throws exceptions</exception>
            public UInt32 GetMachineRegistryKey()
            {
                UInt32 handle;

                try
                {
                    handle = iGroupPolicyObject.GetRegistryKey(GPO_OPTION_DISABLE_MACHINE);
                }
                catch (COMException e)
                {
                    throw e;
                }
                return(handle);
            }
 public RegistryKey GetRootRegistryKey(GroupPolicySection section)
 {
     IntPtr key;
     var result = Instance.GetRegistryKey((uint)section, out key);
     if (result != 0)
     {
         throw new Exception(string.Format("Unable to get section '{0}'", Enum.GetName(typeof(GroupPolicySection), section)));
     }
     var handle = new SafeRegistryHandle(key, true);
     return RegistryKey.FromHandle(handle, RegistryView.Default);
 }
        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);
                }
            }
        }
Exemple #4
0
        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;
        }
Exemple #5
0
        /// <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"));
        }