solomonacquah
asked on
How to retrieve mapped drives and printers of remote machine for whatever user is logged on.
I have written this vb form that allows you to enter a node name and retrieve mapped drives and printers of the machine it is ran on. The Problem is that I need to be able to retrieve this information from remote machines. But do not know how. When I enter a remote machine name It retrieves nothing, but when ran on my machine is retreives everything. Can I use impersonation somehow so that when I enter a remote machine, it will know who is logged onto that machine and then retrieve the mapped drives and printers from that logged on user? thank You
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'On Error Resume Next
Dim objWMIService, strcomputer, colitems, objitem
strcomputer = TextBox1.Text
'get mapped printers
objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\cimv2")
colitems = objWMIService.ExecQuery("S ELECT * FROM Win32_Printer")
For Each objitem In colitems
If objitem.network = True Then
RichTextBox1.Text = RichTextBox1.Text & objitem.deviceID & vbCrLf
End If
Next
'get mapped drives
objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
colitems = objWMIService.ExecQuery("S ELECT * FROM Win32_LogicalDisk where" _
& " Description = 'Network Connection'")
For Each objitem In colitems
RichTextBox2.Text = RichTextBox2.Text & objitem.providername & vbCrLf
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'On Error Resume Next
Dim objWMIService, strcomputer, colitems, objitem
strcomputer = TextBox1.Text
'get mapped printers
objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\cimv2")
colitems = objWMIService.ExecQuery("S
For Each objitem In colitems
If objitem.network = True Then
RichTextBox1.Text = RichTextBox1.Text & objitem.deviceID & vbCrLf
End If
Next
'get mapped drives
objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
colitems = objWMIService.ExecQuery("S
& " Description = 'Network Connection'")
For Each objitem In colitems
RichTextBox2.Text = RichTextBox2.Text & objitem.providername & vbCrLf
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much Graye
ASKER