[英]Simple question about Registry CreateSubKey
为什么这不起作用? 我正在尝试在[HKEY_LOCAL_MACHINE \\ SOFTWARE \\ MyService]下创建一个注册表项,但没有创建任何内容。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Win32;
namespace RegistryKey
{
class Program
{
static void Main(string[] args)
{
const string SUB_KEY_NAME = @"SOFTWARE\MyService";
// Create a subkey named MyService under HKEY_LOCAL_MACHINE.
Registry.LocalMachine.CreateSubKey(SUB_KEY_NAME);
}
}
}
更新:没关系。 我是个白痴。 我使用远程注册表编辑器检查注册表,相信它将显示与regedit相同。 它没有! 我可以使用regedit查看路径。
您没有HKLM的写入权限。 如果你想在这里写,那么你需要:
试试这段代码:
RegistryKey regkey = Registry.CurrentUser;
regkey = regkey.CreateSubKey(SUB_KEY_NAME); //this is the path then you create yours keys
regkey.SetValue("Install", "ok"); //name of key exp:(install) and then the value exp:(ok)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.