读书人

没有权限写注册表,怎么解决

发布时间: 2012-03-06 20:47:55 作者: rapoo

没有权限写注册表,如何解决.
我是在系统管理员账户下运行调试的.可以读,可是就是不能写注册表.
写注册代码如下:

private void checkautorun_CheckedChanged(object sender, EventArgs e)
{
RegistryKey key = Registry.CurrentUser;
RegistryKey subkey = key.OpenSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\ ");


if (checkautorun.Checked)
{

subkey.SetValue( "autobackup ", System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
else
{
subkey.DeleteValue( "autobackup ");
}
}

[解决办法]

RegistryKey key = Registry.CurrentUser;
RegistryKey subkey = key.OpenSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\ ");
改为
RegistryKey key = Registry.LocalMachine;
RegistryKey subkey = key.OpenSubKey
( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run ",true)

[解决办法]
默认是只读打开的

http://msdn2.microsoft.com/zh-cn/library/xthy8s8d(VS.80).aspx

读书人网 >C#

热点推荐