注册表编程:指定的路径无效!有经验的进来看看

flcandclf 2005-03-02 02:31:23
using System;
using Microsoft.Win32;

namespace ConsoleApplication1
{
class Class1
{

[STAThread]
public static void Main(string[] args)
{
RegistryKey key = Registry.CurrentUser;
RegistryKey key2 = key.CreateSubKey("\\Software\\Microsoft\\Windows\\Current Version\\Policies\\Explorer");
key2.SetValue("NoRecentDocsMenu",1);//隐藏开始菜单中文档项
key2.SetValue("NoFind",1);//隐藏开始菜单中查找项
key2.Close();
}

}
}
错误信息:指定的路径无效
...全文
575 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
applelppa 2005-03-02
  • 打赏
  • 举报
回复
RegistryKey software = Registry.CurrentUser.OpenSubKey ("SOFTWARE",true);

RegistryKey pcdesk = software.CreateSubKey ("Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer");

pcdesk.SetValue ("NoRecentDocsMenu",1)
flcandclf 2005-03-02
  • 打赏
  • 举报
回复
谢谢上楼,已经成功了,但我奇怪的是书上怎么这样写啊,我看的是c#教程电子版的,难道就不能直接指定路径啊?
lzy 2005-03-02
  • 打赏
  • 举报
回复
路径要逐层进入,见如下代码:

string subPath=@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer";

string separatorChar=@"\";
char[] separator=separatorChar.ToCharArray();
string[] myPaths=subPath.Split(separator);

RegistryKey regKey1=Registry.CurrentUser;
RegistryKey regKey2=Registry.CurrentUser;

for (int i = 0; i < myPaths.Length; i++)
{
regKey2=regKey1.OpenSubKey(myPaths[i],true);
if (regKey2==null)
regKey1=regKey1.CreateSubKey(myPaths[i]);
else
regKey1=regKey2;
}

regKey1.SetValue("NoRecentDocsMenu",1);

regKey1.Close();
regKey2.Close();
flcandclf 2005-03-02
  • 打赏
  • 举报
回复
命苦啊,这么长时间都没人回应一下,是问题太难还是分太少?解决了分可以再加啊,那怕是有人顶那么一小下我都知足啊!
flcandclf 2005-03-02
  • 打赏
  • 举报
回复
再顶!怎么没人啊
flcandclf 2005-03-02
  • 打赏
  • 举报
回复
自己先顶点人气

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧