0

我是 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

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

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

4

1 回答 1

0
  1. I think the app need to run as administrator (or UAC is causing the problem) to edit the registry and
  2. I use

    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()
    

I think it's almost the same?

于 2014-03-06T12:16:02.920 回答