我正在尝试使用C#按组策略设置更改某些窗口设置 我的应用程序成功地在组策略对象部分中创建子键, 但有时候他们没有工作 例如,我尝试使用组策略禁用桌面,我采取以下步骤:
Process monitor
并将其配置为向我显示与mmc.exe相关的注册表更改我复制Process monitor
中显示的注册表更改并使用它
在我的应用程序中这样:
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
并像这样使用它:
string regPath = @"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer";
string option = "NoDesktop";
SetGroupPolicySetting(regPath, option, 1);
SetGroupPolicySetting使用可从here下载的dll,其编写方式如下:
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();
}
之后,创建了两个子键:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}Machine
和
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}User
最后在此地址中创建了Explorer部分中的NoDesktop选项:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\{27D2FEFF-E5C6-4D8B-B657-0D1E1F2E4BAE}User\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
虽然仍然无法正常工作!怎么了 ?它让我疯了!