IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

[VB.NET] Accès à des fichiers de la Base de Registre


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 9
    Par défaut [VB.NET] Accès à des fichiers de la Base de Registre
    Bonjour à tous,


    J'essaye d'extraire des données depuis des fichiers SAM, SECURITY,SYSTEM,etc... présents sur un disque dur externe connecté à un poste d'analyse. Malheureusement je ne sais pas comment procéder.

    Il existe effectivement des méthodes simples d'accès à la base de registre sur un système tournant mais je n'ai rien trouvé pour lire les clés contenues sur ces fichiers "distants".

    Si l'un d'entre vous peut me faire profiter d'une bonne idée je l'en remercie d'avance

    Etant débutant, n'hésitez pas à détailler la procédure.

    A titre d'exemple j'essaye d'accéder à des données comme la date d'installation d'un système Windows à partir de la clé HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate

    Merci à tous ceux qui prendront le temps de me lire et bonne journée.

    Thierry

  2. #2
    Membre Expert
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Billets dans le blog
    7
    Par défaut
    Bonsoir,

    Pour pouvoir accéder aux ruches contenues dans ces fichiers (SOFTWARE, SYSTEM, ...) il te faudra créer un emplacement temporaire dans le registre de ton système hôte.

    Personnellement j'utilise cette classe (adaptée à mon Soft bien sur) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    '/////////////////////////////////////////////////////////////////////////////////
    '///////////////////////////////// MAJ 28/10/09
    '/////////////////////////////////////////////////////////////////////////////////
     
    Imports Microsoft.VisualBasic.CompilerServices
    Imports Microsoft.VisualBasic
    Imports Microsoft.Win32
    Imports System.ComponentModel
    Imports System
    Imports System.Runtime.InteropServices
     
     
    Namespace Registre
     
        Friend NotInheritable Class mReg
     
            Public Shared MainRK As RegistryKey
            Public Shared ObjLVI As ListViewItem
            Public Shared ObjRK As RegistryKey
            Public Shared EachItem As String
     
            Private Shared hBlob As IntPtr
            Public Const HKEY_LOCAL_MACHINE As UInt32 = 2147483650
            Private Shared MyToken As IntPtr
            Private Shared regKey As RegistryKey
            Private Const SE_BACKUP_NAME As String = "SeBackupPrivilege"
            Private Const SE_PRIVILEGE_ENABLED As UInt32 = 2
            Private Const SE_RESTORE_NAME As String = "SeRestorePrivilege"
            Private Shared strKeyName As String
            Private Const TOKEN_ADJUST_PRIVLEGES As UInt32 = 32
            Private Const TOKEN_QUERY As UInt32 = 8
            Private Shared TP1 As TOKEN_PRIVILEGES
            Private Shared TP2 As TOKEN_PRIVILEGES
            Public Shared WIMt As Boolean
     
            Private Structure LUID
                Private lowPart As UInt32
                Private highPart As Integer
            End Structure
     
            Private Structure LUID_AND_ATTRIBUTES
                Public luid As mReg.LUID
                Public attributes As UInt32
            End Structure
     
            Private Structure TOKEN_PRIVILEGES
                Public PrivilegeCount As UInt32
                Public Privileges As mReg.LUID_AND_ATTRIBUTES
     
                Public Function Size() As Integer
                    Return Marshal.SizeOf(Me)
                End Function
            End Structure
     
            Shared Sub New()
                mReg.WIMt = False
            End Sub
     
            <DllImportAttribute("advapi32", EntryPoint:="AdjustTokenPrivileges", CharSet:=CharSet.Ansi, ExactSpelling:=False, SetLastError:=True, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
             BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
            <PreserveSigAttribute()> _
            Private Shared Function AdjustTokenPrivileges(ByVal TokenHandle As IntPtr, ByVal DisableAllPrivileges As Integer, ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Integer, ByRef PreviousState As TOKEN_PRIVILEGES, ByRef ReturnLength As Integer) As Integer
            End Function
     
            <DllImportAttribute("advapi32", EntryPoint:="LookupPrivilegeValue", CharSet:=CharSet.Ansi, ExactSpelling:=False, SetLastError:=True, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
             BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
            <PreserveSigAttribute()> _
            Private Shared Function LookupPrivilegeValue(ByVal lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LUID) As Integer
            End Function
     
            <DllImportAttribute("advapi32", EntryPoint:="OpenProcessToken", CharSet:=CharSet.None, ExactSpelling:=False, SetLastError:=True, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
             BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
            <PreserveSigAttribute()> _
            Private Shared Function OpenProcessToken(ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As UInt32, ByRef TokenHandle As IntPtr) As Integer
            End Function
     
            <DllImportAttribute("advapi32", EntryPoint:="RegUnLoadKey", CharSet:=CharSet.Ansi, ExactSpelling:=False, SetLastError:=True, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
            BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
           <PreserveSigAttribute()> _
           Public Shared Function RegUnLoadKey(ByVal hKey As UInt32, ByVal lpSubKey As String) As Integer
            End Function
     
            <DllImportAttribute("advapi32", EntryPoint:="RegLoadKey", CharSet:=CharSet.Ansi, ExactSpelling:=False, SetLastError:=True, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
           BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
          <PreserveSigAttribute()> _
          Public Shared Function RegLoadKey(ByVal hKey As UInt32, ByVal lpSubKey As String, ByVal lpFile As String) As Integer
            End Function
     
            <DllImportAttribute("kernel32", EntryPoint:="GetCurrentProcess", CharSet:=CharSet.None, ExactSpelling:=False, SetLastError:=False, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
            BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
            <PreserveSigAttribute()> _
            Private Shared Function GetCurrentProcess() As IntPtr
            End Function
     
            Public Shared Sub DelKey(ByVal Loc As RegistryKey, ByVal Key As String)
                Dim string1 As String = Nothing
     
                Dim registryKey2 As RegistryKey = Nothing
                Dim string2 As String = Nothing
                Try
                    Dim registryKey1 As RegistryKey = Loc.OpenSubKey(Key, True)
                    If Not registryKey1 Is Nothing Then
                        string2 = Key
                        While string2.Contains("\")
                            string2 = string2.Substring(1)
                        End While
                        string1 = Key.Substring(0, (DirectCast((Key.Length - (string2.Length + 1)), Integer)))
                        registryKey2 = Loc.OpenSubKey(string1, True)
                        registryKey2.DeleteSubKeyTree(string2)
                    End If
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
            Public Shared Sub DelValue(ByVal Loc As RegistryKey, ByVal Key As String, ByVal Reg As String)
                Dim exception1 As Exception = Nothing
                Try
                    mReg.regKey = Loc.OpenSubKey(Key, True)
                    mReg.regKey.DeleteValue(Reg, False)
                    mReg.regKey.Close()
                Catch exception2 As Exception
                    exception1 = exception2
                    ProjectData.SetProjectError(exception1)
                    Dim msgBoxResult1 As MsgBoxResult = Interaction.MsgBox(exception1.Message, MsgBoxStyle.Critical, "Error!")
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
            Public Shared Function RegCheckMounted(ByVal Key As String) As Object
                Dim registryKey1 As RegistryKey = Nothing
                Dim b1 As Boolean = False
                Try
                    registryKey1 = Registry.LocalMachine.OpenSubKey(Key, RegistryKeyPermissionCheck.ReadSubTree)
                    Dim object2 As Object = registryKey1.GetValue("(Default)")
                    b1 = True
                    registryKey1.Close()
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    b1 = False
                    ProjectData.ClearProjectError()
                End Try
                Return b1
            End Function
     
            Public Shared Sub RegStart()
                Dim lUID1 As LUID = New LUID()
                Dim tOKEN_PRIVILEGES1 As TOKEN_PRIVILEGES = New TOKEN_PRIVILEGES()
                Dim lUID2 As LUID = New LUID()
                Dim intPtr1 As IntPtr = mReg.GetCurrentProcess()
                If mReg.OpenProcessToken(intPtr1, 40, mReg.MyToken) = 0 Then
                    Throw New Win32Exception()
                End If
                If mReg.LookupPrivilegeValue((DirectCast(Nothing, String)), "SeRestorePrivilege", lUID2) = 0 Then
                    Throw New Win32Exception()
                End If
                If mReg.LookupPrivilegeValue((DirectCast(Nothing, String)), "SeBackupPrivilege", lUID1) = 0 Then
                    Throw New Win32Exception()
                End If
                mReg.TP1.PrivilegeCount = 1
                mReg.TP1.Privileges.attributes = 2
                mReg.TP1.Privileges.luid = lUID2
                Dim i1 As Integer = 0
                If mReg.AdjustTokenPrivileges(mReg.MyToken, 0, mReg.TP1, mReg.TP1.Size(), tOKEN_PRIVILEGES1, i1) = 0 Then
                    Throw New Win32Exception()
                Else
                    mReg.TP2.PrivilegeCount = 1
                    mReg.TP2.Privileges.attributes = 2
                    mReg.TP2.Privileges.luid = lUID1
                    If mReg.AdjustTokenPrivileges(mReg.MyToken, 0, mReg.TP2, mReg.TP2.Size(), tOKEN_PRIVILEGES1, i1) = 0 Then
                        Throw New Win32Exception()
                    End If
                End If
            End Sub
            Public Shared Sub RegStop()
                Dim tOKEN_PRIVILEGES1 As TOKEN_PRIVILEGES = New TOKEN_PRIVILEGES()
                Dim tOKEN_PRIVILEGES2 As TOKEN_PRIVILEGES = New TOKEN_PRIVILEGES()
                Dim i1 As Integer = 0
                tOKEN_PRIVILEGES2 = tOKEN_PRIVILEGES1
                If mReg.AdjustTokenPrivileges(mReg.MyToken, 0, mReg.TP1, mReg.TP1.Size(), tOKEN_PRIVILEGES2, i1) = 0 Then
                    Throw New Win32Exception()
                Else
                    tOKEN_PRIVILEGES2 = tOKEN_PRIVILEGES1
                    If mReg.AdjustTokenPrivileges(mReg.MyToken, 0, mReg.TP2, mReg.TP2.Size(), tOKEN_PRIVILEGES2, i1) = 0 Then
                        Throw New Win32Exception()
                    End If
                End If
            End Sub
     
            Public Shared Sub TakeOwn(ByVal F As String, ByVal Chemin As String)
                Dim string1 As String = Nothing
                Dim string2 As String = Nothing
                If Operators.CompareString(F, "", False) = 0 Then
                    string1 = Chemin & "\Windows\System32\Config\"
                    string2 = Chemin & "\Users\Default\"
                    Dim i1 As Integer = Interaction.Shell(("takeown.exe /F """ + string1 + "SOFTWARE"" /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Dim i2 As Integer = Interaction.Shell(("takeown.exe /F """ + string1 + "COMPONENTS"" /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Dim i3 As Integer = Interaction.Shell(("takeown.exe /F """ + string1 + "SAM"" /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Dim i4 As Integer = Interaction.Shell(("takeown.exe /F """ + string1 + "DEFAULT"" /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Dim i5 As Integer = Interaction.Shell(("takeown.exe /F """ + string1 + "SECURITY"" /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Dim i6 As Integer = Interaction.Shell(("takeown.exe /F """ + string1 + "SYSTEM"" /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Dim i7 As Integer = Interaction.Shell(("takeown.exe /F """ + string2 + "NTUSER.DAT"" /A /R /D O"), AppWinStyle.Hide, False, -1)
     
                    Module1.WaitToFinish("takeown")
                    Dim i8 As Integer = Interaction.Shell(("icacls " + string1 + "SOFTWARE /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Dim i9 As Integer = Interaction.Shell(("icacls " + string1 + "COMPONENTS /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Dim i10 As Integer = Interaction.Shell(("icacls " + string1 + "SAM /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Dim i11 As Integer = Interaction.Shell(("icacls " + string1 + "DEFAULT /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Dim i12 As Integer = Interaction.Shell(("icacls " + string1 + "SECURITY /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Dim i13 As Integer = Interaction.Shell(("icacls " + string1 + "SYSTEM /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Dim i14 As Integer = Interaction.Shell(("icacls " + string2 + "NTUSER.DAT /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
     
                    Module1.WaitToFinish("icacls")
                Else
                    Dim i15 As Integer = Interaction.Shell(("takeown.exe /F """ + F + """ /A /R /D O"), AppWinStyle.Hide, False, -1)
                    Module1.WaitToFinish("takeown")
                    Dim i16 As Integer = Interaction.Shell(("icacls """ + F + """ /grant administrateurs:F /t"), AppWinStyle.Hide, False, -1)
                    Module1.WaitToFinish("icacls")
                End If
            End Sub
     
            Public Shared Sub WriteKey(ByVal Loc As RegistryKey, ByVal Key As String, ByVal Reg As String, ByVal Value As String, ByVal Kind As RegistryValueKind)
     
                Dim registryKey2 As RegistryKey = Nothing
                Dim string1 As String = Nothing
                Dim string2 As String = Nothing
                Dim exception1 As Exception = Nothing
                Dim string3 As String = Nothing
                If mReg.WIMt Then
                    string3 = Loc.ToString()
                    If Operators.CompareString(string3, "HKEY_CURRENT_USER", False) = 0 Then
                        Loc = Registry.LocalMachine
                        Key = ("WIM_Default\" + Key)
                    ElseIf Operators.CompareString(string3, "HKEY_LOCAL_MACHINE", False) = 0 Then
                        If Key.ToUpper().StartsWith("SOFTWARE") Then
                            While Not Key.StartsWith("\")
                                Key = Key.Substring(1)
                            End While
                        End If
                        Key = ("WIM_Software\" + Key)
                    End If
                End If
                Dim registryKey1 As RegistryKey = Loc.OpenSubKey(Key, True)
                If Not registryKey1 Is Nothing Then
                    string1 = Key
                    While string1.Contains("\")
                        string1 = string1.Substring(0, (DirectCast((string1.Length - 1), Integer)))
                    End While
                    string2 = Key
                    While (Not string2.StartsWith("\"))
                        string2 = string2.Substring(1)
                    End While
                    While string2.StartsWith("\")
                        string2 = string2.Substring(1)
                    End While
                    registryKey2 = Loc.OpenSubKey(string1, True)
                    Dim registryKey3 As RegistryKey = registryKey2.CreateSubKey(string2)
                End If
                mReg.regKey = Loc.OpenSubKey(Key, True)
                Try
                    mReg.regKey.SetValue(Reg, Value, Kind)
                    mReg.regKey.Close()
                Catch exception2 As Exception
                    exception1 = exception2
                    ProjectData.SetProjectError(exception1)
                    Dim msgBoxResult1 As MsgBoxResult = Interaction.MsgBox(exception1.Message, MsgBoxStyle.Critical, "Error!")
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
        End Class
     
        Public Class MyClsBlnREG_DWORD
     
            Public Shared Function RegIsSeted(ByVal SubKey As String, ByVal ValueName As String) As Boolean
                Dim flag As Boolean
                Try
                    mReg.ObjRK = mReg.MainRK.OpenSubKey(SubKey)
                    If Operators.ConditionalCompareObjectEqual(mReg.ObjRK.GetValue(ValueName), 1, False) Then
                        Return True
                    End If
                    flag = False
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    flag = False
                    ProjectData.ClearProjectError()
                    Return flag
                    ProjectData.ClearProjectError()
                End Try
                Return flag
            End Function
     
            Public Shared Function RegIsSeted(ByVal Reserve As Boolean, ByVal SubKey As String, ByVal ValueName As String) As Boolean
                Dim flag As Boolean
                If Reserve Then
                    Try
                        mReg.ObjRK = mReg.MainRK.OpenSubKey(SubKey)
                        Dim valueNames As String() = mReg.ObjRK.GetValueNames
                        Dim i As Integer
                        For i = 0 To valueNames.Length - 1
                            mReg.EachItem = valueNames(i)
                            If ((mReg.EachItem.ToLower = ValueName.ToLower) AndAlso Operators.ConditionalCompareObjectEqual(mReg.ObjRK.GetValue(ValueName), 0, False)) Then
                                Return True
                            End If
                        Next i
                        flag = False
                    Catch exception1 As Exception
                        ProjectData.SetProjectError(exception1)
                        flag = False
                        ProjectData.ClearProjectError()
                        Return flag
                        ProjectData.ClearProjectError()
                    End Try
                End If
                Return flag
            End Function
     
            Public Shared Sub SetRegValue(ByVal SubKey As String, ByVal ValueName As String, ByVal value As Boolean)
                Try
                    mReg.ObjRK = mReg.MainRK.CreateSubKey(SubKey)
                    If value Then
                        mReg.ObjRK.SetValue(ValueName, 1, RegistryValueKind.DWord)
                    Else
                        mReg.ObjRK.DeleteValue(ValueName, False)
                    End If
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
            Public Shared Sub SetRegValue(ByVal Reserve As Boolean, ByVal SubKey As String, ByVal ValueName As String, ByVal value As Boolean)
                Try
                    If Reserve Then
                        mReg.ObjRK = mReg.MainRK.CreateSubKey(SubKey)
                        If value Then
                            mReg.ObjRK.SetValue(ValueName, 0, RegistryValueKind.DWord)
                        Else
                            mReg.ObjRK.DeleteValue(ValueName, False)
                        End If
                    End If
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    Dim exception As Exception = exception1
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
        End Class
     
        Public Class MyClsBlnREG_SZ
     
            Public Shared Function RegIsSeted(ByVal SubKey As String, ByVal ValueName As String, ByVal strTrueValue As String) As Boolean
                Dim flag As Boolean
                Try
                    mReg.ObjRK = mReg.MainRK.OpenSubKey(SubKey)
                    If (Conversions.ToString(mReg.ObjRK.GetValue(ValueName)).ToLower = strTrueValue.ToLower) Then
                        Return True
                    End If
                    flag = False
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    flag = False
                    ProjectData.ClearProjectError()
                    Return flag
                    ProjectData.ClearProjectError()
                End Try
                Return flag
            End Function
     
            Public Shared Sub SetRegValue(ByVal SubKey As String, ByVal ValueName As String, ByVal strTrueValue As String, ByVal value As Boolean)
                Try
                    mReg.ObjRK = mReg.MainRK.CreateSubKey(SubKey)
                    If value Then
                        mReg.ObjRK.SetValue(ValueName, strTrueValue, RegistryValueKind.String)
                    Else
                        mReg.ObjRK.DeleteValue(ValueName, False)
                    End If
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
        End Class
     
        Public Class MyClsREG_DWORD
     
            Public Shared Function GetRegValue(ByVal SubKey As String, ByVal ValueName As String) As Integer
                Dim num As Integer
                Try
                    mReg.ObjRK = mReg.MainRK.OpenSubKey(SubKey)
                    num = Conversions.ToInteger(mReg.ObjRK.GetValue(ValueName, -1))
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
                Return num
            End Function
     
            Public Shared Sub SetRegValue(ByVal SubKey As String, ByVal ValueName As String, ByVal IntValue As Integer)
                Try
                    mReg.ObjRK = mReg.MainRK.CreateSubKey(SubKey)
                    mReg.ObjRK.SetValue(ValueName, IntValue, RegistryValueKind.DWord)
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
        End Class
     
        Public Class MyClsREG_SZ
     
            Public Shared Function GetRegValue(ByVal SubKey As String, ByVal ValueName As String) As String
                Try
                    mReg.ObjRK = mReg.MainRK.OpenSubKey(SubKey)
                    Return Conversions.ToString(mReg.ObjRK.GetValue(ValueName, ""))
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
                Return ""
            End Function
     
            Public Shared Sub SetRegValue(ByVal SubKey As String, ByVal ValueName As String, ByVal strValue As String)
                Try
                    mReg.MainRK.CreateSubKey(SubKey).SetValue(ValueName, strValue, RegistryValueKind.String)
                Catch exception1 As Exception
                    ProjectData.SetProjectError(exception1)
                    ProjectData.ClearProjectError()
                End Try
            End Sub
     
            Public Shared Sub refreshRegistry()
     
                Registry.ClassesRoot.Close()
                Registry.CurrentUser.Close()
                Registry.LocalMachine.Close()
                Registry.Users.Close()
                Registry.CurrentConfig.Close()
            End Sub
     
        End Class
     
    End Namespace
    Comment l'utiliser :


    Je vérifie qu'aucune instance (fenêtre regedit) ne soit ouverte auquel cas je la ferme. Accessoirement je ferme les ruches qui sont ouvertent. Et enfin je décharge les ruche avant de lancer la procédure pour charger les ruches que je souhaite (ca évite les problèmes).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     Private Sub RegUnload()
     
            Dim r As Process
            Dim p = Process.GetProcessesByName("regedit")
            For Each r In p
                r.Kill()
            Next
     
            MyClsREG_SZ.refreshRegistry()
     
            Dim i9 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_Software")
            Dim i10 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_Default")
            Dim i11 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_SAM")
            Dim i12 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_Security")
            Dim i13 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_System")
            Dim i14 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_Components")
            Dim i15 As Integer = mReg.RegUnLoadKey((DirectCast(2147483650, Long)), "WIM_UserDat")
     
        End Sub
    Je charge les ruches nécessairent dans le registre du système hôte grace à la classe plus haut. La classe permet d'avoir le controle total sur les fichiers (SOFTWARE, SYSTEM, USER.DAT,...) pour permettre leur modifications.
    Je vérifie que les ruches sont bien montées grace à la routine "RegCheckMounted".


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
        Private Sub RegLoad()
     
            Dim string1 As String
            Dim string2 As String
            Dim string3 As String
            mReg.RegStart()
            string1 = FBD2.SelectedPath
            string2 = FBD2.SelectedPath & "\Windows\system32\Config\"
            string3 = FBD2.SelectedPath & "\Users\Default\"
            mReg.TakeOwn("", string1)
            Dim i1 As Integer = mReg.RegLoadKey((DirectCast(2147483650, Long)), "WIM_Software", (string2 + "SOFTWARE"))
            Dim i5 As Integer = mReg.RegLoadKey((DirectCast(2147483650, Long)), "WIM_System", (string2 + "SYSTEM"))
            Dim i7 As Integer = mReg.RegLoadKey((DirectCast(2147483650, Long)), "WIM_UserDat", (string3 + "NTUSER.DAT"))
     
            If Operators.ConditionalCompareObjectEqual(mReg.RegCheckMounted("WIM_Software\"), False, False) Then
                msgBox("Un problème est survenu!!!")
            End If
    Après pour lister les clés du registre je suppose que tu sauras te débrouiller le cas échéant une solution parmi tant d'autres :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
      Dim key As Microsoft.Win32.RegistryKey
            key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall", False)
     
            Dim t() As String = key.GetSubKeyNames
     
            For i As Integer = 0 To t.Length - 1
     
                dlgBox.ListBox1.Items.Add(t(i))
     
            Next
    Voilà bon courage.


    EDIT : j'ai oublier de te fournir les routines suivantes :

    OpenProgram() et waitToFinish() c'est ici :

    http://www.developpez.net/forums/d84...f/#post4840658

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 9
    Par défaut
    Merci beaucoup wallace1 pour toutes ces informations qui correspondent pile poil à ce que je cherchais...reste plus qu'à tout comprendre et à tout implémenter...

    Encore un grand merci d'avoir pris le temps de me répondre et cela de façon aussi claire....

    Réponse du feignant qui sommeille en moi... : il n'y aurait pas un exécutable qui permettrait d'accéder en lecture seule à ses fichiers / clés via une simple ligne de commande ?

    allez j'ai du boulot maintenant

    Thierry

  4. #4
    Membre Expert
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Billets dans le blog
    7
    Par défaut
    Citation Envoyé par thierry922010 Voir le message
    ....
    .......

    Réponse du faignant qui sommeille en moi... : il n'y aurait pas un exécutable qui permettrait d'accéder en lecture seule à ses fichiers / clés via une simple ligne de commande ?

    allez j'ai du boulot maintenant

    Thierry
    Il n'existe pas à ma connaissance d'exécutable permettant de lire directement ce genres de fichiers, on est obligé de les fusionner aux ruches du registre. C'est une question de sécurité en fait.

    Une autre solution tu peux tout aussi bien utiliser la classe process comme ceci pour Monter tes fichiers et charger tes ruches :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Public Sub regMount()
        Me.procinfo = New Process
        Me.procinfo.StartInfo.FileName = "reg.exe"
        Dim Prc1 As ProcessStartInfo = Me.procinfo.StartInfo
        Prc1.Arguments = ("Load HKLM\Test """ & Me.MountDir & "\windows\system32\config\SOFTWARE")
        Prc1.CreateNoWindow = True
        Prc1.UseShellExecute = False
        Prc1.RedirectStandardOutput = False
        Prc1 = Nothing
        Me.procinfo.Start
        Do While Not Me.procinfo.WaitForExit(100)
        Loop
        Me.procinfo.Close
        Me.procinfo = New Process
        Me.procinfo.StartInfo.FileName = "reg.exe"
        Dim Prc2 As ProcessStartInfo = Me.procinfo.StartInfo
        Prc2.Arguments = ("Load HKLM\Test """ & Me.MountDir & "\windows\system32\config\system")
        Prc2.CreateNoWindow = True
        Prc2.UseShellExecute = False
        Prc2.RedirectStandardOutput = False
        Prc2 = Nothing
        Me.procinfo.Start
        Do
            Application.DoEvents
        Loop While Not Me.procinfo.WaitForExit(100)
        Me.procinfo.Close
    End Sub
    Pour démonter :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Public Sub regUnMount()
        Me.procinfo = New Process
        Me.procinfo.StartInfo.FileName = "reg.exe"
        Dim Prc3 As ProcessStartInfo = Me.procinfo.StartInfo
        Prc3.Arguments = "UnLoad HKLM\Test"
        Prc3.CreateNoWindow = True
        Prc3.UseShellExecute = False
        Prc3.RedirectStandardOutput = False
        Prc3 = Nothing
        Me.procinfo.Start
        Do
            Application.DoEvents
        Loop While Not Me.procinfo.WaitForExit(100)
        Me.procinfo.Close
        Me.procinfo = New Process
        Me.procinfo.StartInfo.FileName = "reg.exe"
        Dim Prc4 As ProcessStartInfo = Me.procinfo.StartInfo
        Prc4.Arguments = "UnLoad HKLM\Test"
        Prc4.CreateNoWindow = True
        Prc4.UseShellExecute = False
        Prc4.RedirectStandardOutput = False
        Prc4 = Nothing
        Me.procinfo.Start
        Do
            Application.DoEvents
        Loop While Not Me.procinfo.WaitForExit(100)
        Me.procinfo.Close
    End Sub
    Il faudra au préalable utiliser la routine "OpenProgram()" sur le fichier que tu comptes charger dans le registre pour permettre sa modification.

    Allez j'arrête. Bon courage.

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 9
    Par défaut
    bon bah je crois qu'une réponse plus complète cela va être difficile !

    Je vais essayer de m'atteler aux deux solutions pour voir laquelle est la plus pratique pour moi.

    Un grand merci pour ton aide détaillée.

    Thierry

    2 questions en passant :

    -le montage et le démontage consistent en l'insertion du contenu des fichiers dans la base de registre de mon ordi d'analyse mais alors comment distinguer les clés d'origine (de l'ordi d'analyse) et celles du fichier distant qui auront la même architecture ?
    -le montage et le démontage ne laissent aucune trace dans la base de registre du système d'analyse ?

  6. #6
    Membre Expert
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Billets dans le blog
    7
    Par défaut
    Citation Envoyé par thierry922010 Voir le message
    2 questions en passant :

    -le montage et le démontage consistent en l'insertion du contenu des fichiers dans la base de registre de mon ordi d'analyse mais alors comment distinguer les clés d'origine (de l'ordi d'analyse) et celles du fichier distant qui auront la même architecture ?
    -le montage et le démontage ne laissent aucune trace dans la base de registre du système d'analyse ?
    Avant de te lancer dans cet aventure je te conseille de tester le résultat avec une copie par exemple du fichier "SOFTWARE". Tu lances la ligne de commande avec une invite (cmd) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    reg load HKLM\test c:\windows\system32\config\SOFTWARE
    Rends-toi dans ton registre et observe le résultat en recherhant la branche :
    "HKEY_LOCAL_MACHINE\Test"

    Comment interpréter cette commande; c'est simple :

    --> reg load : prêt à charger une ruche (SOFTWARE, SYSTEM,...)
    --> HKLM\Test : ca permet de créer une branche nommée "Test" dans la ruche "HKEY_LOCAL_MACHINE" de ton système hôte.
    --> c:\windows\system32\config\SOFTWARE : C'est le chemin complet du fichier que tu souhaites charger dans la branche "HKEY_LOCAL_MACHINE\Test" de ton système hôte.

    Pour décharger la ruche directement sans passer par la ligne de commande tu sélectionnes la branche dans le registre puis depuis le "Menu/Fichier/Décharger la ruche".

    Il n'y a effectivement aucunes traces dans la base de registre du système hôte. Il faut penser à bien décharger les ruches en vérifiant qu'elle ne sont pas en cours d'utilisation bien sur en libérant les resources.

    J'espère avoir été clair. Si c'est pas le cas bah n'hésites pas

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. accés à des fichiers *.db
    Par wincroc dans le forum Bases de données
    Réponses: 4
    Dernier message: 16/08/2005, 14h48
  2. Interet de mettre des fichiers dans une base de donnée
    Par Oberown dans le forum Décisions SGBD
    Réponses: 7
    Dernier message: 04/07/2005, 11h35
  3. [C#] [.NET CF] des fichiers de données avec l'application
    Par safisoft13 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 06/06/2005, 09h30
  4. Chemin d'accès des fichiers dans des sous rep
    Par Le Veilleur dans le forum C++Builder
    Réponses: 4
    Dernier message: 17/11/2004, 14h37
  5. Restreindre l'accès des fichiers..
    Par Neilos dans le forum Windows
    Réponses: 6
    Dernier message: 25/08/2004, 00h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo