Jag vill kunna lägga in en liten checkbox där man snyggt kryssar för att programmet ska startas när Windows startas. Lägga till i AutostartAutostart
Men hur i hela världen ser koden ut för det, egentligen?
Jag vill inte dra nån genväg till autostart-mappen... utan jag vill att den ska ändra själva autostart som startar upp diverse program i början... Som i MSN Messenger, för att få ett bra exempel..
Nån som vet??!?Sv: Autostart
'modul
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal szData As String, ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
'Form
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Dim RetVal As Long
Dim phkResult As Long
Dim SubKey As String
Dim Key As Long
Dim Value As Variant
Dim Data As String
Key = HKEY_LOCAL_MACHINE
SubKey = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Value = "Programmets namn"
Data = "C:\mitt_program.exe"
RetVal = RegCreateKey(Key, SubKey, phkResult)
RetVal = RegSetValueEx(phkResult, Value, 0, 1, Data, CLng(Len(Data) + 1))
RegCloseKey phkResult
'Och använd detta för att ta bort från Autostart
'modul
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hkey As Long, ByVal lpValueName As String) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
'Form
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Dim RetVal As Long
Dim phkResult As Long
Dim SA As SECURITY_ATTRIBUTES
Dim SubKey As String
Dim Key As Long
Dim Value As String
Key = HKEY_LOCAL_MACHINE
SubKey = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Value ="Programmets namn"
RetVal = RegCreateKeyEx(Key, SubKey, 0, "", 0, 63, SA, phkResult, Create)
RetVal = RegDeleteValue(phkResult, Value)
RegCloseKey phkResult