fb:porticula NoPaste
FBP-Betatest
Uploader: | Jojo |
Datum/Zeit: | 20.03.2008 14:45:45 |
Attribute VB_Name = "modAutostart"
Option Explicit
DefInt A-Z
'zunächst die benötigten API-Deklarationen
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 RegSetValueEx_String Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK
Const ERROR_SUCCESS = 0&
Const REG_NONE = 0
Const REG_SZ = 1
Public Function SetAutoRun(sDescr As String, sPath As String) As Boolean
Dim lResult As Long
Dim KeyHandle As Long
Dim Key As String
Const root = HKEY_CURRENT_USER
Key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
lResult = RegOpenKeyEx(root, Key, 0, KEY_ALL_ACCESS, KeyHandle)
If lResult <> ERROR_SUCCESS Then
SetAutoRun = False
Exit Function
End If
lResult = RegSetValueEx_String(KeyHandle, sDescr, 0, REG_SZ, sPath, Len(sPath) + 1)
RegCloseKey KeyHandle
SetAutoRun = (lResult = ERROR_SUCCESS)
End Function
Function RemoveAutoRun(sDescr As String) As Boolean
Dim lResult As Long
Dim KeyHandle As Long
Dim Key As String
Const root = HKEY_CURRENT_USER
Key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
lResult = RegOpenKeyEx(root, Key, 0, KEY_ALL_ACCESS, KeyHandle)
If lResult <> ERROR_SUCCESS Then
RemoveAutoRun = False
Exit Function
End If
lResult = RegDeleteValue(KeyHandle, sDescr)
RemoveAutoRun = (lResult = ERROR_SUCCESS)
RegCloseKey KeyHandle
End Function