Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Const REG_SZ = 1
Const HKEY_CURRENT_USER = &H80000001Private Sub Command1_Click()
  Unload Me
End SubPrivate Sub Form_Load()
Text1.Text = App.Path & "\" & App.EXEName & ".exe"
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   Dim hkey As Long
   Dim strruncmd As String
   strruncmd = Text1.Text
   Call RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\Currentversion\Runonce", hkey)
   Call RegSetValueEx(hkey, "xxxx", 0&, REG_SZ, ByVal strruncmd, Len(strruncmd) + 1)
   Call RegCloseKey(hkey)
   MsgBox "下次开机程序回自动启动"
End Sub