Public Const REG_SZ = 1
Public Const HKEY_CURRENT_USER = &H80000001
Private Sub Form_QueryUnload (Cancel as Integer, UnloadMode as Integer)
Dim hKey As Long
Dim strRunCmd As String
If UnloadMode = vbAppWindows Then
strRunCmd = App.Path & "\" & App.EXEName & ".EXE"
Call RegCreateKey(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows\CurrentVersion\RunOnce", hKey)
Call RegSetValueEx(hKey, "MyApp", 0&, REG_SZ, _
ByVal strRunCmd, Len(strRunCmd)+1)
Call RegCloseKey(hKey)
Endif
End Sub