注册表权限问题 [英] Registry permission problem

查看:80
本文介绍了注册表权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个注册表项,以便Windows启动时我的应用程序运行,我尝试了以下代码:

I need to create a registry key so that my application runs when windows starts, and I tried the following code:

string strRegKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
string path = \\path of my application
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(strRegKey, true);
regkey = Registry.LocalMachine.CreateSubKey(strRegKey);
regkey.SetValue("sys", path, RegistryValueKind.String);



编译器在regkey.SetValue:
处给出了错误
试图执行未经授权的操作"

请告诉我我该如何解决这个问题?



The compiler gave an error at regkey.SetValue:

"Attempted to perform an unauthorized operation"

Please tell me how I can solve this problem?

推荐答案

谢谢! 我将我的代码修改如下:
thank you Wjousts
i modifed my code to be like this :
string strRegKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
string path = \\path of my application 
RegistryKey regkey = Registry.LocalMachine.CreateSubKey(strRegKey);
regkey.SetValue("sys", path, RegistryValueKind.String);


然后我得到了例外:
UnauthorizedAccessException
告诉我注册表项是只读的
所以我怎么写到这个位置,因为Windows启动时有很多程序通过将exe文件的路径写入注册表中的这个位置来运行.
我尝试了它的手册,它奏效了,但是我想在我的应用程序中做到这一点.
因此,您能帮我吗?


and then i got exception:
UnauthorizedAccessException
that told my that registry key is read only
so how can i write to this location because many program run when windows startup by writing the path of exe file to this location in registry .
and i tried it manual and it worked but i want to do it in my application .
so can you help me


您正在写HKLM,如果有存储空间,我认为您需要管理员权限才能执行此操作.您是否以管理员身份运行应用程序?如果没有,您可以尝试写信给HKCU. HKCU显然只会影响当前用户,而不影响使用计算机的所有人,而这可能或可能不是您要使用的计算机.
You are writing to HKLM, if memory serves, I think you need administrator access to do that. Are you running your app as administrator? If not, you could try writing to HKCU instead. HKCU obviously will only effect the current user rather than everybody who uses the computer which may or may not be what you are trying to do.


再次感谢您!Wjousts
我试图以管理员"身份运行我的应用程序,并且该应用程序有效
而且我会尝试以当前用户"的身份写信而无需以管理员身份运行我的应用程序.
但我的问题只发生在Vista系统中
因此,谢谢您的回答非常有帮助
thank you again Wjousts
i tried to run my application "as adminstrator" and its worked
and i will tring to write in "current user" without running my application as adminstrator .
but my problem only happened in vista system
so thank you your answers were very helpful


这篇关于注册表权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆