Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


List mapped drives on remote machine

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,28529
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> List mapped drives on remote machine
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 List mapped drives on remote machine - 12/1/2005 9:50:15 PM   
  ginolard


Posts: 1023
Score: 21
Joined: 8/10/2005
Status: offline
Improved version of the code that gets the currently logged on user.


      

< Message edited by ginolard -- 5/30/2006 8:18:52 PM >
 
 
Revisions: 1 | Post #: 1
 
 RE: List mapped drives on remote machine - 10/16/2006 11:42:37 PM   
  gurner78

 

Posts: 7
Score: 0
Joined: 10/16/2006
Status: offline
Or, borrowing from your script, i need to know who and what mapped drives have been created on workstations by the users in a very disjointed domain, to try and control via a GPO/KIX/VBS type logon script to query AD.  so I came up with this variation of your script, to put in a central NETLOGON Share as a VBS file to upload the mapped drive details for a user to a share on a NAS box

and marked in Red my additions

**********************************************************
'Define variables, constants and objects

'define text file and username

Const ForAppending = 8
Const OverwriteExisting = TRUE

dim WSHNetwork, UserString
set WSHNetwork = CreateObject("WScript.Network")
UserString = WSHNetwork.UserName

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
   ("" & UserString & ".txt", ForAppending, True)


' rest

strComputer="localhost"
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
                  objTextFile.WriteLine subkey & ":" & vbTab & dapath
          Next
               objTextFile.Close
          End If
      End If
  End If
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "" & UserString & ".txt" , "\\nas1\Map\", OverwriteExisting


************************************************

_____________________________

Cheers

(in reply to ginolard)
 
 
Post #: 2
 
 RE: List mapped drives on remote machine - 10/17/2006 6:22:17 PM   
  ginolard


Posts: 1023
Score: 21
Joined: 8/10/2005
Status: offline
If you're going to be running this script as part of a logon script then you really don't need to do it this way.  You can use WMI to get the Mapped drive information by querying Win32_LogicalDisk Where DriveType=4

The only drawback of that method (and the reason I created the above code) is that it won't work when run against a REMOTE machine.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to gurner78)
 
 
Post #: 3
 
 RE: List mapped drives on remote machine - 12/1/2006 1:31:32 AM   
  vehemeni

 

Posts: 1
Score: 0
Joined: 12/1/2006
Status: offline

Hey,
Your script is awesome!

But it only lists the drives that were mapped by the logged in user on his own, how about drives that were mapped by a logon script?
Can you help with this?
Thanks,
e.Mirandda

(in reply to gurner78)
 
 
Post #: 4
 
 RE: List mapped drives on remote machine - 12/1/2006 2:15:52 AM   
  ginolard


Posts: 1023
Score: 21
Joined: 8/10/2005
Status: offline
Unfortunately I've never found a way to do this remotely.  It's very frustrating because WMI almost promises to do it with Win32_LogicalDisk or Win32_NetworkConnection but doesn't return all the info when run against remote machines.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to vehemeni)
 
 
Post #: 5
 
 RE: List mapped drives on remote machine - 12/4/2006 12:25:19 AM   
  ginolard


Posts: 1023
Score: 21
Joined: 8/10/2005
Status: offline
Well, I guess I spoke too soon.

It's not pretty but it's fast and it works.


      

< Message edited by ginolard -- 12/4/2006 12:51:05 AM >


_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ginolard)
 
 
Revisions: 1 | Post #: 6
 
 RE: List mapped drives on remote machine - 5/22/2007 7:04:16 PM   
  kremlin


Posts: 1
Score: 0
Joined: 5/21/2007
Status: offline
Hello,

This is my first reply in forum, so i could make some mistakes.
I found this script very useful for collecting data from
logged in computers, so i made some modifications that i could use it in logonscript and collect information
into remote server shared folder.
My users couldnt save temp file into c:\ directly so i had to redirect this file into user temp folder.
After data is collected this file is copied into \\server\log\folder\ and log file in local pc is deleted.
Script is tested with group policy and it works.


      

(in reply to ginolard)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> List mapped drives on remote machine Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts