Link to home
Start Free TrialLog in
Avatar of solomonacquah
solomonacquahFlag for United States of America

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("SELECT * 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("SELECT * FROM Win32_LogicalDisk where" _
         & " Description = 'Network Connection'")

        For Each objitem In colitems
            RichTextBox2.Text = RichTextBox2.Text & objitem.providername & vbCrLf

               Next
    End Sub
Avatar of solomonacquah
solomonacquah
Flag of United States of America image

ASKER

refund please
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much Graye