Hej . Dim keyname As String ' receives name of each subkeyScanna registryt INTE läs/skriv enstaka nyckelvärden..
Någon som har ett tips på hur man scannar registryt ?
Vad jag vill är att ta reda på vilka printrar som är kopplade.
I HKEY_CURRENT_USER\Printers\connections\... ligger alla kopplade printrar som nycklar, varje nyckel har ett namn som talat om vilkem printserver och skrivarkö.
Detta är lagrat som en Nyckel och inte som nyckelvärden.
Hur scannan man ????
Att läsa enstaka värden vet jag hur man gör men inte att leta nycklar...
//Micke Sv: Scanna registryt INTE läs/skriv enstaka nyckelvärden..
Dim keylen As Long ' length of keyname
Dim classname As String ' receives class of each subkey
Dim classlen As Long ' length of classname
Dim lastwrite As FileTime ' receives last-write-to time, but we ignore it here
Dim hkey As Long ' handle to the HKEY_LOCAL_MACHINE\Software key
Dim index As Long ' counter variable for index
Dim retval As Long ' function's return value
' Open the desired registry key. Note the access level requested.
retval = RegOpenKeyEx(HKEY_CURRENT_USER, "Printers\connections", 0, KEY_ENUMERATE_SUB_KEYS, hkey)
' Test to make sure the key was opened successfully.
If retval <> 0 Then
'Debug.Print "Registry key could not be opened -- aborting."
Exit Sub ' terminate the program
End If
' List through each possible subkey. Note how the strings receiving the information
' must be reinitialized each loop iteration.
index = 0 ' initial index value
While retval = 0 ' while we keep having success (retval equals 0 from the above API call)
keyname = Space(255): classname = Space(255) ' make room in string buffers
keylen = 255: classlen = 255 ' identify the allocated space
' Get information about the next subkey, if one exists.
retval = RegEnumKeyEx(hkey, index, keyname, keylen, ByVal 0, classname, classlen, lastwrite)
If retval = 0 Then ' only display info if another subkey was found
' Extract the useful information from the string buffers.
keyname = Left(keyname, keylen) ' trim off the excess space
classname = Left(classname, classlen)
' Display the returned information.
MsgBox keyname
End If
index = index + 1 ' increment the index counter
Wend ' end the loop
' Close the registry key after enumeration is complete.
retval = RegCloseKey(hkey)
prova denna kod
mvh
johan