首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

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

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

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

热点排行