尝试添加注册表项时出现未处理的异常 [英] Unhandled Exception when trying to add registry key
问题描述
当我使用以下代码时My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
When I use the following code My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
要添加一个注册表项以使我的程序自动启动,它可以在我的系统上运行,但是对于我发送给它的每个人都会收到一条未处理的异常"消息,说明访问被拒绝.我想知道是否有解决方案.谢谢
to add a registry key to make my program startup automatically, it works on my system but on everyone who I have sent it to gets an "Unhandled Exception" message saying that access is denied. I was wondering if there is a solution to this. Thanks
推荐答案
您得到 拒绝访问" 因为如果您想写入 HKEY_LOCAL_MACHINE
键.
You get "Access denied" because you are required to run your app with administrative privileges if you want to write to the HKEY_LOCAL_MACHINE
key.
您可以通过执行以下步骤强制您的应用仅以管理员权限运行,因此始终要求管理员权限:
You can force your app to only run with, and therefore always ask for, admin privileges by doing the following steps:
在 Visual Studio 的
Solution Explorer
窗口中右键单击您的项目,然后按Properties
.
Right-click your project in Visual Studio's
Solution Explorer
window and pressProperties
.
确保您位于 Application
选项卡上,然后按下显示 View Windows Settings
的按钮.
Make sure you are on the Application
tab, then press the button that says View Windows Settings
.
在编辑器中打开的 app.manifest
文件中,找到以下内容:
In the app.manifest
file that opens in the editor locate the following:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
并将其替换为:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
这篇关于尝试添加注册表项时出现未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!