在启动时运行vb.net应用程序

时间:2013-12-23 20:53:37

标签: .net vb.net startup regedit

我是vb.net的初学者,我坚持将我的应用程序设置到启动寄存器,我用谷歌搜索了很多不同的代码,但到目前为止没有人能为我工作!

这个(我在stackoverflow上搜索时发现他)与vb.net不兼容,你需要权限(许可证)来执行此操作:

   Imports Microsoft.Win32
   Public Class Form1

Private Sub Form1_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
End Class

所以我尝试了这个:

   Dim CU As Microsoft.Win32.RegistryKey = _
Registry.CurrentUser.CreateSubKey _
("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
    With CU
.OpenSubKey("SOFTWARE\Microsoft\Windows\ _CurrentVersion\Run", True)
        .SetValue("login.exe", "C:\Users\evert\Documents\Visual Studio 2010\Projects\login\login\bin\Debug\")
    End With

不会工作,因为当我查看我的注册表时它没有出现?

我需要一个答案,我的朋友们无法帮助我:( 我希望你们能帮助我!最好的问候我!

1 个答案:

答案 0 :(得分:0)

  1. 我认为该应用需要以管理员身份运行(或UAC导致问题)来编辑注册表和
  2. 我用

    Dim regKey As Microsoft.Win32.RegistryKey
    regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
    regKey.SetValue(Application.ProductName, """" & Application.ExecutablePath & """")
    regKey.Close()
    
  3. 我认为它几乎一样?

相关问题