日期:2014-05-19  浏览次数:20853 次

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

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