1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| Option Explicit
Dim lng As Long
Dim Buff As Long
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_DYN_DATA = &H80000004
Public Enum HCle
HKeyLocalMachine = 0
HKeyCurrentUser = 1
HKeyClassesRoot = 2
HKeyUsers = 3
HKeyDynamicData = 4
End Enum
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
(ByVal HKey As Long, _
ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
(ByVal HKey As Long, _
ByVal lpSubKey As String) As Long
Public Function CreerCle(HK As HCle, Chemin As String) As Long
RegCreateKey HKConvert(HK), Chemin, lng
CreerCle = lng
End Function
Private Function HKConvert(HK As HCle) As Long
If HK = 2 Then HKConvert = HKEY_CLASSES_ROOT
If HK = 1 Then HKConvert = HKEY_CURRENT_USER
If HK = 0 Then HKConvert = HKEY_LOCAL_MACHINE
If HK = 3 Then HKConvert = HKEY_USERS
If HK = 4 Then HKConvert = HKEY_DYN_DATA
End Function
Public Function SupprCle(HK As HCle, Chemin As String)
RegDeleteKey HKConvert(HK), Chemin
End Function
Public Function DonnerValeur(HK As HCle, Chemin As String, Valeur As String, Donnee As String)
RegCreateKey HKConvert(HK), Chemin, lng
RegSetValueEx lng, Valeur, 0&, 1, Donnee, Len(Donnee) + 1
End Function
Public Function LireValeur(HK As HCle, Chemin As String, Valeur As String) As String
Buff = 0
Buff = RegCreateKey(HKConvert(HK), Chemin, lng)
If Buff = 0 Then RegQueryValueEx lng, Valeur, 0&, 1, 0&, Buff
If Buff < 2 Then
LireValeur = ""
Exit Function
End If
LireValeur = String(Buff + 1, " ")
RegQueryValueEx lng, Valeur, 0&, 1, ByVal LireValeur, Buff
LireValeur = Left(LireValeur, Buff - 1)
End Function
Public Function SupprValeur(HK As HCle, Chemin As String, Valeur As String)
Buff = 0
Buff = RegCreateKey(HKConvert(HK), Chemin, lng)
If Buff = 0 Then RegDeleteValue lng, ByVal Valeur
End Function
Public Sub Run(Parametre As String)
DonnerValeur HKeyLocalMachine, "Software\Microsoft\Windows\CurrentVersion\Run", App.Title, App.Path & "\" & App.EXEName & ".exe " & Parametre
End Sub
Public Function IsRun() As Boolean
If LireValeur(HKeyLocalMachine, "Software\Microsoft\Windows\CurrentVersion\Run", App.Title) <> "" Then IsRun = True Else IsRun = False
End Function
Public Sub DelRun()
SupprValeur HKeyLocalMachine, "Software\Microsoft\Windows\CurrentVersion\Run", App.Title
End Sub
SupprValeur HKeyLocalMachine, "System\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}", john |
Partager