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

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

Open in new window


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

Open in new window

Jono MartinSystems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, unfortunately, you can't.  As you've stated, you can view the PERSISTENT drives of a remote user by querying the HKCU\Network key, but that's all you can see remotely.

If you want the current drives, you need to have the user run the code you have for EnumNetworkDrives.  The script could then pipe that to a file for you to read.

I have not found any way of reading the non persistent drives that a remote user has mapped.

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewCommented:
Rob,

Just a thought, but could we use PSEXEC to run some code on the target machine(s)?

~bp
0
RobSampsonCommented:
No, because it needs to run under the user context....
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Bill PrewCommented:
Well, I guess if you knew the username and password for each remote computer you could specify them to PSEXEC, but I get that doesn't work.

So only other approach is to actually run a logon script on the desired PCs and write the output to a shared folder or such, where it could be collected.

~bp
0
RobSampsonCommented:
Yeah, pretty much.  That still misses out on any later made connections that are not persistent though.  It's always been a pain!
0
Bill PrewCommented:
Gotcha.

~bp
0
Jono MartinSystems AdministratorAuthor Commented:
Thanks guys.  That's a drag that it can't be done, but I'm glad that at least I know not to spend any more hours trying to figure out the VBS for something that will never work.

Thanks again!
Jono
0
RobSampsonCommented:
Sure, no problem.

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.