troubleshooting Question

VBS to find all mapped drives on remote computer and print to txt file

Avatar of Jono Martin
Jono MartinFlag for United States of America asked on
ProgrammingNetworkingVB Script
8 Comments1 Solution2100 ViewsLast Modified:
Hello,

I am not very familiar with VBS, but I've been able to put together 2 scripts to almost give me what I want (the resulting script is posted below).  I have seen scripts that present what the HKCU>Network shows as the mapped drives, but I wanted to be presented with all mapped drives, including Home folder, and drives mapped to other computers.

I also have a script that will present to me all of my drives, but it shows my mapped drives even when I ask for the mapped drives of a remote computer.

The code below works, except that, as stated, it gives me the user and computer name of the remote computer and the drives of my computer.  I need it to show me the drives of the remote computer.

This is what the script gives me:
    User: training1
Computer: floater8

Drive H: = \\server\home$\jmartin
Drive U: = \\seperate_computer\Docs
Drive P: = \\server\san-PRIVATE-data
Drive S: = \\server\san-SHARED-data

This is the correct format, the computer name (floater8) is the correct remote computer and the user name is the user that's currently logged into that computer.  All of that is correct.  The drives, however, are the drives on my computer, not the target computer.

What can I change in the code that will give me the drives of the remote computer?

Thanks,
Jono

P.S.  I'm sure the code is not very clean and neat; like I said, I'm not very familiar with VBS.  I just need it to work.
' ********** My Code **********

strComputer = inputbox("enter computer name")
Set Connect = GetObject("winmgmts://"&strComputer)
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections

' ********** Blank the report message
strMsg = ""

' ********** Set objects 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objWbem = GetObject("winmgmts:")
Set objRegistry = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")

' ********** Get the current user from Explorer  
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

' ********** Print user and computer
strMsg = strMsg & "    User: " & sUser & VbCrLf
strMsg = strMsg & "Computer: " & strComputer & VbCrLf & VbCrLf

For i = 0 to oDrives.Count - 1 Step 2
strMsg = strMsg & "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) & VbCrLf
Next

'For i = 0 to oPrinters.Count - 1 Step 2
'strMsg = strMsg & "Printer " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1) & VbCrLf
'Next

' ********** Check for the existence of the "SysInfoCheck" folder then
' ********** write the file to disk.
strDirectory = "C:\SysInfoCheck"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDirectory) Then
	' Procede
Else
	Set objFolder = objFSO.CreateFolder(strDirectory)
End if
' ********** Calculate date serial for filename **********
intMonth = month(now)
if intMonth < 10 then
	strThisMonth = "0" & intMonth
else
	strThisMonth = intMOnth
end if
intDay = Day(now)
if intDay < 10 then
	strThisDay = "0" & intDay
else
	strThisDay = intDay
end if
strFilenameDateSerial = year(now) & strThisMonth & strThisDay
	Set objFile = objFSO.CreateTextFile(strDirectory & "\" & strComputer & "_" & sUser & "_MappedDrives" & "_" & strFilenameDateSerial & ".txt",True)	
objFile.Write strMsg & vbCrLf

' ********** Ask to view file
strFinish = "Finished collecting mapped drives for computer: " & strComputer & "." & VbCrLf & VbCrLf & "View file?"
strAnswer=MsgBox(strFinish, 68, "System Information Checker")
if strAnswer = 6 then
	Set objShell = CreateObject("WScript.Shell")
	objShell.run strDirectory & "\" & strComputer & "_" & sUser & "_MappedDrives" & "_" & strFilenameDateSerial & ".txt"
end if
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros