I want to Export the Users Mapped Drives on One Machine. i found the below Script but it doesn't work
I need the txt file with the Computer name and inside it each user with his mapped Drive.
'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" , "\\02-maroon-02\Package Sources\Applications\MapDrive Logs\", OverwriteExisting
Thanks Bill Prew. but your script will give me all users the logged in the machine and their maooed drive even if they logged off ? or only the online users ?
Thanks
Bill Prew
My script will report on the mapped drives of the currently sctive user that ran the script.
~bp
Fady AbuZuaiter
ASKER
Thanks for your reply. Can we make it for all users?
' List Mapped Network Drives
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colItems = objWMIService.ExecQuery("S
For Each objItem in colItems
Wscript.Echo "Compressed: " & objItem.Compressed
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "File System: " & objItem.FileSystem
Wscript.Echo "Free Space: " & objItem.FreeSpace
Wscript.Echo "Maximum Component Length: " & objItem.MaximumComponentLe
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Provider Name: " & objItem.ProviderName
Wscript.Echo "Session ID: " & objItem.SessionID
Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
Wscript.Echo "Supports File-Based Compression: " & _
objItem.SupportsFileBasedC
Wscript.Echo "Volume Name: " & objItem.VolumeName
Wscript.Echo "Volume Serial Number: " & objItem.VolumeSerialNumber
Wscript.Echo
Next