Toon posts:

[VB] Register mappen uitlezen...

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hoi, zit met een vraagstuk.

Ik zou graag willen inventariseren in onze eigen inventory tool (vb) welke Hotfixes en Patches zijn geïnstalleerd in windows. Deze staan in het register in windows onder:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows 2000
(in ons geval de 2000 machines)

Binnen deze key staan (op het moment) 3 mapjes; SP2, SP3, SP5. Die zijn weer onderverdeeld in de mappen voor de hotfixes. Zo heb je dus een mapje voor de laatste sasser update:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows 2000\SP5\KB841720

Hoe kan ik al die sub folders in een string zetten?

Dus dat je in één string krijgt; KB841720,KB835732,KB828749 ... etc.

Heb het een en ander geprobeerd:
code:
1
2
3
    Set sh = CreateObject("wscript.shell")
        bKey = sh.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows 2000")
    Set sh = Nothing


Dit werkt echter (natuurlijk) niet. Zou echter niet weten hoe je die mapjes kan ophalen. Een leuk detail is dat er misschien binnenkort SP6 uitkomt, en deze automatisch meegepakt moet worden...

Ben benieuwd welke antwoorden jullie hebben.

Alvast erg bedankt!!!

  • Ashtaroth
  • Registratie: December 2003
  • Laatst online: 16-02 09:59
Gebruik volgende APIs:
E.e.a. is gekoppiepasta'd uit standaard component, dus kan wat aanpassingen vereisen.

Visual Basic:
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
 
'\\ The RegOpenKeyEx function opens the specified key.
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

'\\ The RegEnumKeyEx function enumerates subkeys of the specified open registry key.
'\\ The function retrieves information about one subkey each time it is called.
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
            (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
             lpcbName As Long, lpReserved As Long, ByVal lpClass As String, _
             lpcbClass As Long, lpftLastWriteTime As udtFileTime) As Long

'\\ Enumeration of the Main Keys in the Registry.
Public Enum enmRegRoot
    [HKEY_CLASSES_ROOT] = &H80000000     'OLE class info and file associations
    [HKEY_CURRENT_USER] = &H80000001     'All the info for the current user
    [HKEY_LOCAL_MACHINE] = &H80000002    'program info for all users
    [HKEY_USERS] = &H80000003            'All the info for any user
    [HKEY_PERFORMANCE_DATA] = &H80000004
    [HKEY_CURRENT_CONFIG] = &H80000005   'computer configuration info
    [HKEY_DYN_DATA] = &H80000006         'dynamic data about installed hard- and software
End Enum

Public Const KEY_ENUMERATE_SUB_KEYS = &H8   'Permission to enumerate subkeys.
Public Const ERROR_SUCCESS              As Long = 0&


Public Function EnumerateRegKeys(ByVal strKeyPath As String, _
                        Optional ByVal lngRootKey As enmRegRoot = HKEY_LOCAL_MACHINE) As String()
On Error GoTo Error_Enumerate

    Dim lngKeyHandle            As Long     'handle to the opened registry key
    Dim lngRetVal               As Long     'return value
    Dim lngIndex                As Long     'counter
    Dim lngStrings              As Long     'counter
    Dim strBuffer               As String
    Dim lngBufferSize           As Long
    Dim strBufferClassName      As String
    Dim lngBufferSizeClassName  As Long
    Dim udtLastWrite            As udtFileTime
    Dim arrKeys()               As String

    '\\ Open the registry key.
    lngRetVal = RegOpenKeyEx(lngRootKey, strKeyPath, 0&, KEY_ENUMERATE_SUB_KEYS, _
                             lngKeyHandle)
    '\\ Check to see if an error occured.
    If lngRetVal <> ERROR_SUCCESS Then Call Err.Raise(lngRetVal)
    
    lngIndex = 0
    '\\ Loop until no more registry keys.
    Do Until lngRetVal <> ERROR_SUCCESS
        '\\ Allocate buffers.
        strBuffer = Space(255)
        strBufferClassName = Space(255)
        lngBufferSize = 255
        lngBufferSizeClassName = 255
        '\\ Get key names.
        lngRetVal = RegEnumKeyEx(lngKeyHandle, lngIndex, strBuffer, lngBufferSize, _
                                 ByVal 0&, strBufferClassName, lngBufferSizeClassName, _
                                 udtLastWrite)
        If lngRetVal = ERROR_SUCCESS Then
            '\\ Redimension the array.
            ReDim Preserve arrKeys(lngStrings) As String
            '\\ Read the buffers.
            strBuffer = Left$(strBuffer, lngBufferSize)
            strBufferClassName = Left$(strBufferClassName, lngBufferSizeClassName)
            '\\ Fill the array.
            arrKeys(lngStrings) = strBuffer
            lngStrings = lngStrings + 1
        End If
        lngIndex = lngIndex + 1
    Loop
    
Exit_Enumerate:
    '\\ Close the registry key.
    lngRetVal = RegCloseKey(lngKeyHandle)
    EnumerateRegKeys = arrKeys()
    Exit Function

Error_Enumerate:
    arrKeys() = Empty
    Call WriteLastError(Err.Number, Err.Description)
    Resume Exit_Enumerate
    
End Function

  • Ashtaroth
  • Registratie: December 2003
  • Laatst online: 16-02 09:59
Nog ff opmerking:
De functie retourneert een array, in jouw geval moet de functie een comma seperated string terugsturen. In dat geval moet je het ReDim Preserve statement wijzigen in een concatination.