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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| Imports Microsoft.Win32
Imports System.IO
Imports System.Data.OleDb
Imports System.Text
Imports System
Imports System.Security.Permissions
'Il faut mettre en référence des dll téléchargés depuis le site developpez.com
'Ce sont des dll d'aide complète pour l'ensemble des fonctionnalités vb.net
'Ici cela me sers a utiliser plus facilement les fichiers ini
Module ModuleRegistry
Public MyConnection As OleDbConnection = New OleDbConnection()
Public MyCommand As OleDbCommand = MyConnection.CreateCommand()
Public MyReader As OleDbDataReader
Public CheminCle As String
Public CleRegistre As String
Public PrefixeKey As String
Public environmentKey As RegistryKey
Public myValue As Object
Public mypass As String
Public strUser As String
Sub ReadKey(ByVal commandLineArgs As String)
Dim imp As New RunAs_Impersonator
imp.ImpersonateStart("domXXX", ModuleRegistry.strUser, ModuleRegistry.mypass)
Select Case PrefixeKey
Case "HKEY_LOCAL_MACHINE"
Try
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.LocalMachine, _
commandLineArgs).OpenSubKey(CheminCle)
Catch ex As IOException
MsgBox("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
Case "HKEY_CURRENT_USER"
Try
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.CurrentUser, _
commandLineArgs).OpenSubKey(CheminCle)
Catch ex As IOException
MsgBox("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
Case "HKEY_USERS"
Try
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.Users, _
commandLineArgs).OpenSubKey(CheminCle)
Catch ex As IOException
MsgBox("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
End Select
MsgBox("La valeur de la clé de registre " & CleRegistre & " est : " & environmentKey.GetValue(CleRegistre))
environmentKey.Close()
imp.ImpersonateStop()
End Sub
Sub ModifKey(ByVal commandLineArgs As String)
Dim imp As New RunAs_Impersonator
imp.ImpersonateStart("domXXX", ModuleRegistry.strUser, ModuleRegistry.mypass)
Select Case PrefixeKey
Case "HKEY_LOCAL_MACHINE"
Try
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.LocalMachine, _
commandLineArgs).OpenSubKey(CheminCle, True)
Catch ex As IOException
MsgBox("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
Case "HKEY_CURRENT_USER"
Try
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.CurrentUser, _
commandLineArgs).OpenSubKey(CheminCle, True)
Catch ex As IOException
MsgBox("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
Case "HKEY_USERS"
Try
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.Users, _
commandLineArgs).OpenSubKey(CheminCle, True)
Catch ex As IOException
MsgBox("{0}: {1}", _
ex.GetType().Name, ex.Message)
Return
End Try
End Select
myValue = InputBox("Choisir la nouvelle valeur", "EditRegistryKey", 0)
If myValue Is "" Then myValue = 0
environmentKey.SetValue(CleRegistre, myValue)
MsgBox("La valeur de la clé de registre " & CleRegistre & " a été changée en : " & environmentKey.GetValue(CleRegistre))
environmentKey.Close()
imp.ImpersonateStop()
End Sub |
Partager