2020年8月15日 星期六

vb.net 開機執行 [Start on StartUp]

1
2
3
4
5
Imports Microsoft.Win32


    Dim regKey As RegistryKey
    Dim strRegKeyName As String = "University PgBot"





1
2
3
4
5
6
7
8
    'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True)
        regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True)
        If regKey.GetValue(strRegKeyName) <> "" And regKey.GetValue(strRegKeyName) = Application.ExecutablePath Then
            chkAutoRun.Checked = True
        End If
    End Sub

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    Private Sub chkAutoRun_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAutoRun.Click
        'regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True)
        regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True)
        If chkAutoRun.Checked = True Then
            regKey.SetValue(strRegKeyName, Application.ExecutablePath)
        Else
            regKey.SetValue(strRegKeyName, "")
        End If
        regKey.Close()
    End Sub

沒有留言:

張貼留言