Option Explicit '-------------------------------------- Private Declare Function RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey&, ByVal lpszSubKey$, lphKey&) Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As LongConst HKEY_LOCAL_MACHINE = &H80000002 Const REG_SZ = 1'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run Private Sub Command1_Click() ' Dim sKeyName As String, sKeyValue As String, sKeyValueIcon As String Dim Ret As Integer, lphKey As Long sKeyName = "Software\Microsoft\Windows\CurrentVersion\Run" sKeyValue = App.Path & IIf(Len(App.Path) > 3, "\" & "form1.exe", "form1.exe") Ret = RegCreateKey&(HKEY_LOCAL_MACHINE, sKeyName, lphKey) Ret = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)End Sub
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon下的 shell 值改为你的程序路径连续启动没有试过,你可以试试用 | 作为分隔符看行不行
'--------------------------------------
Private Declare Function RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey&, ByVal lpszSubKey$, lphKey&)
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As LongConst HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
Private Sub Command1_Click()
'
Dim sKeyName As String, sKeyValue As String, sKeyValueIcon As String
Dim Ret As Integer, lphKey As Long sKeyName = "Software\Microsoft\Windows\CurrentVersion\Run"
sKeyValue = App.Path & IIf(Len(App.Path) > 3, "\" & "form1.exe", "form1.exe")
Ret = RegCreateKey&(HKEY_LOCAL_MACHINE, sKeyName, lphKey)
Ret = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)End Sub