在下面的代码中Registry.LocalMachine.CreateSubKey("Software\\" + Settings.Default.ApplicationName))后,打开注册表后,并没有创建相应的项.但奇怪的是str居然能取到值,为桌面路径,
问题1.为什么会这样
问题2.如何解决
string str = string.Empty;using (RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\" + Settings.Default.ApplicationName))
{
str = key.GetValue("Path", string.Empty).ToString();
}
问题1.为什么会这样
问题2.如何解决
string str = string.Empty;using (RegistryKey key = Registry.LocalMachine.CreateSubKey("Software\\" + Settings.Default.ApplicationName))
{
str = key.GetValue("Path", string.Empty).ToString();
}
HKEY_USERS\<User SID>_Classes\VirtualStore\Machine\Software如果在这里能找到你创建的键,那么你的问题出于Vista的注册表虚拟化:Registry Virtualization解决方法同样参考链接文章(更好的办法是避免写到LocalMachine\SOFTWARE项下)。
RegistryKey rsg = null;
string str="";
rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\A",true);
if (rsg.GetValue("PATH") != null) {
str= rsg.GetValue("path").ToString();
}
else
str = "该键不存在!";
rsg.Close();