Jag har gjort ett program där man kan lägga in en genväg i Autostart. Problemet är att jag vill även kunna ta bort genvägen med programmet. Hur gör jag det? Jag vill inte hårdkoda sökvägen till Autostart eftersom sökvägen kan se olika ut på olika datorer. Jag brukar göra såhär när jag vill att programmet ska starta med Windows.Ta bort en genväg i Autostart
Tack på förhand!Sv: Ta bort en genväg i Autostart
<code>
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) 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
Private Const HKEY_CURRENT_USER = &H80000001
Private Const KEY_WRITE = &H20006
Private Const REG_SZ = 1
Public Sub SetBootRegKey(ByVal strKeyName As String, ByVal strKeyValue As String, bolAutoStart As Boolean)
On Error Resume Next
Dim hKey As Long, stringBuffer As String, retVal As Long
If bolAutoStart Then
retVal = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, hKey)
If retVal <> 0 Then Exit Sub
stringBuffer = strKeyValue & vbNullChar
retVal = RegSetValueEx(hKey, strKeyName, 0, REG_SZ, ByVal stringBuffer, Len(stringBuffer))
RegCloseKey hKey
Else
RegOpenKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", hKey
RegDeleteValue hKey, strKeyName
RegCloseKey hKey
End If
End Sub
</code>
och du kallar den såhär:
<code>
SetBootRegKey "Namn", App.Path & "\" & App.EXEName & ".exe", True
</code>
/Micke