关于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 查看路径。
Why doesn't this work? I am trying to create a registry key under [HKEY_LOCAL_MACHINE\SOFTWARE\MyService], but nothing is created.
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);
}
}
}
Update: Never mind. I'm an idiot. I used the Remote registry Editor to inspect the registry in the belief that it would show the same as regedit. It didn't! I can see the path using regedit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有 HKLM 的写入权限。如果您想在此处编写,那么您需要:
You don't have write access to HKLM. If you want to write here then you need to either:
尝试使用以下代码:
Try with this code: