出现此错误
''System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)''
当我尝试将注册表项添加到注册表时。我提到的应用程序requestedExecutionLevel是"requireAdministrator“。这是一个更好的想法,以启用ClickOnce安全设置,并留下requestedExecutionLevel‘’为asinvoker“?
这是VB.NET代码的结构:
Try
[my code]
Catch sec As Security.SecurityException
[another block of code]
Catch ex As Exception
[another block of code]
End Try
使用“on error resume next”语句是不是更好?请给我解释一下为什么会发生这个错误?
VB.NET,Visual Studio2008( Vindows Vista旗舰版x86和Windows7旗舰版x64出现错误,我是以管理员帐户登录的)
发布于 2012-12-21 07:59:39
用户帐户控制(UAC)甚至需要管理员组帐户来提升应用程序。该提升必须由用户在应用程序通过提交UAC对话框启动时授予。
因此,您需要使用以下命令编辑app.manifest
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
如果您不希望应用程序在每次启动时都触发UAC,您可以将需要提升到另一个可执行文件的操作外包出去,并从未提升的进程中调用它,就像这样
Dim elevatedProc As New Process
elevatedProc.FileName= "elevated.exe"
Try
elevatedProc.Start()
Catch ex As System.ComponentModel.Win32Exception
MsgBox("Please commit UAC dialog")
End Try
如果用户未提交UAC对话框,则会抛出System.ComponentModel.Win32Exception。
或者,您可以在系统帐户下运行的服务中运行您的内容,这将根本不会触发UAC。
https://stackoverflow.com/questions/13952729
复制相似问题