HI ALL!!
I am noob and this is my first post so be gentle
I am trying to list all printers (Printers\Connections)
under all users (HKEY_USERS)
problem is I dont know the user name keys in advance and need to exclude .DEFAULT and *_CLASSES
so first I need to list all key names (%usernamekey%) directly under HKEY_USERS
then for all keys that lists
lsit all keys under HKEY_USERS
\%usernamekey%\Printers\Connections
Here is the code I have so far but I get errors about object variable not set, I suspect because of the way I doing the for each and listing the key names and then doing it again
ANy ideas are appreciated! Many thanks in advance
Code:
Private Sub DetectPrntrs()
Try
Dim RemReg As Microsoft.Win32.RegistryKey
Dim RemVal As String = ""
Dim RemUser As String
RemReg = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.Users, (OldPCTxtBx.Text))
For Each RemUser In RemReg.GetSubKeyNames
Dim RemUserRegKey = RemReg.OpenSubKey(RemUser & "\Printers\Connections")
RemVal = RemUserRegKey.GetSubKeyNames
RemReg.Close()
Next
Dim PrnterKeys = RemVal
For Each PrntrName As String In PrnterKeys
If (PrntrName) = ".DEFAULT" Then
ElseIf (PrntrName) = "_CLASSES" Then
Else
Me.PrintersListBx.Items.Add(PrntrName)
End If
Next
Catch ex As Exception
WriteLog("DetectPrntrs Error :" & TimeOfDay.ToString & " " & ex.Message)
End Try
End Sub