Setting a GPO alone does not make it active. GPOs usually get reapplied at boot or after a certain period of time. You can probably run something like gpupdate /force
(as Administrator) to force reapplying GPOs.
Why doesn't group policy settingS get changed?
-
10-07-2023 - |
Question
I am trying to change some windows settings by group policy settings using C#.
My application creates sub-keys in the group policy objects section successfully,
But some times they doesn't work.
For example i am trying to disable desktop using Group policy, I take these steps :
- I run
Process monitor
and configure it to show me the registry changes relating to mmc.exe - Then run gpedit.msc and navigate to the desired option and change it
I copy the registry change which is shown in
Process monitor
and use it in my app like this :mmc.exe RegSetValue HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{FD0F8A58-1909-410F-8860-4CFF7766FA89}User\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDesktop SUCCESS Type: REG_DWORD, Length: 4, Data: 1
And use it like this :
string regPath = @"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer";
string option = "NoDesktop";
SetGroupPolicySetting(regPath, option, 1);
SetGroupPolicySetting uses a dll which can be downloaded from here and is written like this :
private void SetGroupPolicySetting(string registryKeyPath,
string option,
int value ,
GroupPolicySection groupPolicySection = GroupPolicySection.User)
{
var gpo = new ComputerGroupPolicyObject();
RegistryKey registryKey = gpo.GetRootRegistryKey(groupPolicySection);
registryKey.CreateSubKey(registryKeyPath).SetValue(option, value , RegistryValueKind.DWord);
gpo.Save();
}
After that , there are two subkeys created which are:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}Machine
and
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}User
and finally the NoDesktop option in Explorer section is created in this address :
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}User\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
though still its not working ! Whats wrong ? its driving me insane!
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow