Jump to content

Get mapped drives of remote user/computer


Recommended Posts

Following the advise of the Scripting Guys I have come up with the following that simply will not do what I want it to. I need to run a script against a remote computer and have it tell me the current drive mappings of the currently logged on user. In case any of you are wondering why someone would find this useful, here is an example. Users are calling me all the time asking for the "G" drive or the "T" drive. We have MANY login scripts and letters are reused depending on group membership (I didn't some up with it, just have to live with it). Anyway, the user says "I need the T drive like Jim-Bob has". So I need to know what T is mapped to on Jim-Bob's PC.

$readInput = InputBox("EnterComputer Name", "")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $readInput & "\root\cimv2")
$colDrives = $objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 4")

For $objDrive In $colDrives
    MsgBox(0, "", "Name: " & $objDrive.DeviceID & @CRLF & "Network Path: " & $objDrive.ProviderName & @CRLF)
Next

This works fine against my local PC. I am thinking that there may be some permission issues with pulling this type of information but according to the article, it should work. I can't make it work even when I am the person logged on the remote computer. Any ideas anyone?

In VBS format:

strComputer = WScript.Arguments(0)
     
     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
     Set colDrives = objWMIService.ExecQuery _
         ("Select * From Win32_LogicalDisk Where DriveType = 4")
     
     For Each objDrive in colDrives
         Wscript.Echo " " & objDrive.DeviceID & " drive = " & objDrive.ProviderName
     Next

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Following the advise of the Scripting Guys I have come up with the following that simply will not do what I want it to. I need to run a script against a remote computer and have it tell me the current drive mappings of the currently logged on user. In case any of you are wondering why someone would find this useful, here is an example. Users are calling me all the time asking for the "G" drive or the "T" drive. We have MANY login scripts and letters are reused depending on group membership (I didn't some up with it, just have to live with it). Anyway, the user says "I need the T drive like Jim-Bob has". So I need to know what T is mapped to on Jim-Bob's PC.

$readInput = InputBox("EnterComputer Name", "")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $readInput & "\root\cimv2")
$colDrives = $objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 4")

For $objDrive In $colDrives
    MsgBox(0, "", "Name: " & $objDrive.DeviceID & @CRLF & "Network Path: " & $objDrive.ProviderName & @CRLF)
Next

This works fine against my local PC. I am thinking that there may be some permission issues with pulling this type of information but according to the article, it should work. I can't make it work even when I am the person logged on the remote computer. Any ideas anyone?

In VBS format:

strComputer = WScript.Arguments(0)
     
     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
     Set colDrives = objWMIService.ExecQuery _
         ("Select * From Win32_LogicalDisk Where DriveType = 4")
     
     For Each objDrive in colDrives
         Wscript.Echo " " & objDrive.DeviceID & " drive = " & objDrive.ProviderName
     Next
Remotely connecting to a computer does not give you access to the environment of that computer's local user. You need that user to run your script in their own environment. Post it on a share everyone can see and have "Jim-Bob" run it. He can report the results back, or the script can log the results for you to somewhere "Jim-Bob" has write permissions.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Remotely connecting to a computer does not give you access to the environment of that computer's local user. You need that user to run your script in their own environment. Post it on a share everyone can see and have "Jim-Bob" run it. He can report the results back, or the script can log the results for you to somewhere "Jim-Bob" has write permissions.

:)

Yea... I was really hoping that someone would know what bit to flip to make this work. We kicked around the idea of writing back to a log file but I thought I would post the question first. Thanks.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...