Metti su un modulo: (*.bas)
codice:
Public Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" ( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As Long, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
phkResult As Long, _
lpdwDisposition As Long) As Long
Public 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
Public Declare Function RegCloseKey Lib "advapi32.dll" ( _
ByVal hKey As Long) As Long
'Registry
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const REG_CREATED_NEW_KEY = &H1 ' Creata nuova chiave di registro
Public Const KEY_SET_VALUE = &H2
'RegSetValueEx
Public Const REG_SZ = 1
Poi per far avviare il programma all'avvio:
codice:
stringa = App.Path + "\nomeapplicazione.exe"
RegCreateKeyEx HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, 0, 0, KEY_SET_VALUE, 0, lKey, lresult
RegSetValueEx lKey, "Password Reminder", 0, REG_SZ, ByVal stringa, Len(stringa)
RegCloseKey lKey
Per non farlo più avviare:
codice:
RegCreateKeyEx HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, 0, 0, KEY_SET_VALUE, 0, lKey, lresult
RegSetValueEx lKey, "Password Reminder", 0, REG_SZ, ByVal "", Len("")
RegCloseKey lKey
In questo modo inserisci il nome del tuo programma nel registro di sistema per farlo avviare automaticamente, è più elegante di esecuzione automatica