gpt4 book ai didi

c# - 如何编辑 gpedit 政策

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:15 27 4
gpt4 key购买 nike

请问如何使用 C# 编辑 gpedit.msc 策略?

最佳答案

gpedit.msc 只是注册表设置的一个接口(interface); gpedit 没有 API 或暴露的框架。要像 gpedit 一样操作一个值,您需要操作关联的 RegistryKey .

class RegKey
{
static void Main()
{
// Create a subkey named Test9999 under HKEY_CURRENT_USER.
RegistryKey test9999 =
Registry.CurrentUser.CreateSubKey("Test9999");
// Create two subkeys under HKEY_CURRENT_USER\Test9999. The
// keys are disposed when execution exits the using statement.
using(RegistryKey
testName = test9999.CreateSubKey("TestName"),
testSettings = test9999.CreateSubKey("TestSettings"))
{
// Create data for the TestSettings subkey.
testSettings.SetValue("Language", "French");
testSettings.SetValue("Level", "Intermediate");
testSettings.SetValue("ID", 123);
}

// Print the information from the Test9999 subkey.
Console.WriteLine("There are {0} subkeys under {1}.",
test9999.SubKeyCount.ToString(), test9999.Name);
foreach(string subKeyName in test9999.GetSubKeyNames())
{
using(RegistryKey
tempKey = test9999.OpenSubKey(subKeyName))
{
Console.WriteLine("\nThere are {0} values for {1}.",
tempKey.ValueCount.ToString(), tempKey.Name);
foreach(string valueName in tempKey.GetValueNames())
{
Console.WriteLine("{0,-8}: {1}", valueName,
tempKey.GetValue(valueName).ToString());
}
}
}

using(RegistryKey
testSettings = test9999.OpenSubKey("TestSettings", true))
{
// Delete the ID value.
testSettings.DeleteValue("id");

// Verify the deletion.
Console.WriteLine((string)testSettings.GetValue(
"id", "ID not found."));
}

// Delete or close the new subkey.
Console.Write("\nDelete newly created registry key? (Y/N) ");
if(Char.ToUpper(Convert.ToChar(Console.Read())) == 'Y')
{
Registry.CurrentUser.DeleteSubKeyTree("Test9999");
Console.WriteLine("\nRegistry key {0} deleted.",
test9999.Name);
}
else
{
Console.WriteLine("\nRegistry key {0} closed.",
test9999.ToString());
test9999.Close();
}
}
}

关于c# - 如何编辑 gpedit 政策,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5018672/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com