应用程序启动:::访问错误

问题描述:

嗨 我正在使用以下代码将我的应用程序添加到Windows启动。它在XP中运行良好,但在Vista中出现错误,您无权编辑注册文件。应用程序启动:::访问错误

Private Sub Forceps_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     'Dim regStartUp As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) 

     'Dim value As String 

     'value = regStartUp.GetValue("Myapp") 

     'If value <> Application.ExecutablePath.ToString() Then 

     'regStartUp.CreateSubKey("Myapp") 
     'regStartUp.SetValue("Myapp", Application.ExecutablePath.ToString()) 

     '  End If 

End Sub 

这是由Vista中的用户帐户控制(UAC)功能引起的。 Vista上的管理员(有时是7和Server 2008)使用特权受限的用户令牌运行,除非应用程序明确要求它们。

有关阅读UAC以及如何配置应用程序的链接。

http://en.wikipedia.org/wiki/User_Account_Control

http://technet.microsoft.com/en-us/library/cc709691(WS.10).aspx

http://bartdesmet.net/blogs/bart/archive/2006/10/28/Windows-Vista-2D00-Demand-UAC-elevation-for-an-application-by-adding-a-manifest-using-mt.exe.aspx