Solved

script to get mapped drives

Posted on 2006-11-26
6
1,087 Views
Last Modified: 2010-05-18
Hi, I want to write a script that will show all the mapped drive a user has. This is on a windows xp enviroment. I know that I can use net use or this script. The problem is If I run through psexec it will check  my admin id drives and not the logged on user drive mappings. Any ideas
strComputer = "."
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colDrives = objWMI.ExecQuery("select * from Win32_MappedLogicalDisk")
WScript.Echo "Mapped Drives:"
for each objDrive in colDrives
    WScript.Echo " Device ID: " & objDrive.DeviceID
    WScript.Echo " Volume Name: " & objDrive.VolumeName
    WScript.Echo " Session ID: " & objDrive.SessionID
    WScript.Echo " Size: " & objDrive.Size
    WScript.Echo
next
0
Comment
Question by:tuckcorp
  • 3
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
ch2 earned 500 total points
ID: 18015203
Try this one.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")

For Each objDrive in colDrives
    Wscript.Echo "Drive letter: " & objDrive.DeviceID
    Wscript.Echo "Network path: " & objDrive.ProviderName
Next

http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct05/hey1027.mspx
0
 
LVL 11

Expert Comment

by:ch2
ID: 18015211
0
 
LVL 6

Expert Comment

by:Dark_King
ID: 18018596
If you like PsExec Try to use PsInfo with -d
http://www.microsoft.com/technet/sysinternals/utilities/psinfo.mspx
0
 
LVL 6

Expert Comment

by:Dark_King
ID: 18018657
List mapped drives on remote machine, Improved version of the code that gets the currently logged on user.


'Define variables, constants and objects

strComputer="REMOTE MACHINE HERE"
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objRegistry = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
Set objWMIService = GetObject("winmgmts:"  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Go and get the currently logged on user by checking the owner of the Explorer.exe process.  

Set 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.
lngRtn = objRegistry.EnumKey(HKEY_USERS, "", arrRegKeys)    
   
For Each strKey In arrRegKeys
   If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
   Else

       Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")

'If the account name of the current sid we're checking matches the accountname we're looking for Then
'enumerate the Network subtree
       If objSID.accountname = sUser Then
           regpath2enumerate = strkey & "\Network" 'strkey is the SID
           objRegistry.enumkey hkey_users, regpath2enumerate, arrkeynames
               
'If the array has elements, go and get the drives info from the registry
           If Not (IsEmpty(arrkeynames)) Then
               For Each subkey In arrkeynames
                   regpath = strkey & "\Network\" & subkey
                   regentry = "RemotePath"
                   objRegistry.getstringvalue hkey_users, regpath, regentry, dapath
                   wscript.echo subkey & ":" & vbTab & dapath
               Next
           End If
       End If
   End If
Next
0
 
LVL 6

Expert Comment

by:Dark_King
ID: 18171869
My example off a script work, it list mapped drive for current user.

I have tested to login on a workstation and using “net use” to map some drives on server.
Then from another workstation use “psexec” to copy and execute this script remotely.

It then show the mapped drives I did for this user.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now