converted vbs to vb.net - no errors but not returning data

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<pre class="prettyprint lang-vb here is my code this was converted from .VBS to VB.NET but does not do anything, it should return all printers mapped for all users on a remote pc Private Sub DetectPrntrs()
Try
Const HKEY_USERS = &H80000003
Const ForAppending = 8
Const OverwriteExisting = True
Dim oProcess
Dim strComputer As String = OldPCTxtBx.Text
Dim sUser
Dim sDomain
Dim strarray
Dim Arrkeynames
Dim objWbem = GetObject("winmgmts:")
Dim objRegistry = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
Dim objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Go and get the currently logged on user by checking the owner of the Explorer.exe process.
Dim colProc = objWMIService.ExecQuery("Select Name from Win32_Process" & " Where Name=explorer.exe and SessionID=0")
If colProc.Count > 0 Then
For Each oProcess In colProc
oProcess.GetOwner(sUser, sDomain)
Next
End If
Loop through the HKEY_USERS hive until (ignoring the .DEFAULT and _CLASSES trees) until we find the tree that
corresponds to the currently logged on user.
Dim arrRegKeys As Array
Dim lngRtn = objRegistry.EnumKey(HKEY_USERS, "", arrRegKeys)
Dim StrKey
For Each StrKey In arrRegKeys
If (StrKey).toupper = ".DEFAULT" Or (Microsoft.VisualBasic.Right(StrKey, 8).ToUpper) = "_CLASSES" Then
Else
Dim objSID = objWbem.Get("Win32_SID.SID=" & StrKey & "")
If the account name of the current sid were checking matches the accountname were looking for Then
enumerate the Network subtree
If objSID.accountname = sUser Then
Dim regpath2enumerate = StrKey & "PrintersSettings" strkey is the SID
objRegistry.enumkey(HKEY_USERS, regpath2enumerate, Arrkeynames)
If the array has elements, go and get the drives info from the registry
Dim intCount = 0
Dim subkey
If Not (IsDBNull(Arrkeynames)) Then
For Each subkey In Arrkeynames
Dim dapath
Dim regpath = StrKey & "PrintersSettings" & subkey
Dim regentry = "RemotePath"
objRegistry.getstringvalue(HKEY_USERS, regpath, regentry, dapath)
intCount = intCount + 1 increment
Dim arrRead = sUser & vbTab & subkey & ":" & vbTab & dapath & vbTab & vbLf
strarray = strarray & arrRead
Next
PrintersListBx.Items.Add(strarray)
WriteLog(strarray)
Else
WriteLog("No printers defined")
End If
End If
End If
Next
Catch ex As Exception
WriteLog("DetectPrntrs Error :" & TimeOfDay.ToString & " " & ex.Message)
End Try
End Sub [/code]
<br/><hr class="sig David Sheetz MCP

View the full article
 
Back
Top