Gathering mapped drive information remotely

I have the script below that I am attempting to use to gather mapped drive information for the currently logged in user remotely. The script works fine on XP machines but will not work with Windows 7. What am I missing?

I am not a vbscript writer by any stretch of the imagination. I have compiled it by taking snippets from code that I have found online and modifying it.

Any help would be greatly appreciated.
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.OpenTextFile("C:\scripts\output.txt",8,True)

'Define variables, constants and objects

compid = InputBox("Enter Computer Name","Gather Mapped Drives for Current Logged on User")
strComputer=compid
objOutputFile.WriteLine "Computer Name: " & strComputer
objOutputFile.WriteLine "----------------------------------------"

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
					objOutputFile.WriteLine subkey & ":" & vbTab & dapath
					'wscript.echo subkey & ":" & vbTab & dapath
				Next
			End If
		End If
	End If
Next
objOutputFile.WriteLine ""
objoutputFile.WriteLine "Current Logged In User: " & suser
objOutputFile.WriteLine "Ran on:" & Now
objOutputFile.WriteLine "________________________________________"
objOutputFile.WriteLine ""
objOutputFile.WriteLine ""


objoutputFile.Close

Open in new window

blkstrimAsked:
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:
For this to work, the drive MUST be a persistent mapping.  That's the only time it puts it in the Network key.  I have tested it and it worked, although I changed SessionID to 2 because I had RDP'd to the Windows 7 machine.

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
blkstrimAuthor Commented:
Rob,
Thanks for the help. That lead me in the right direction to complete the script to work with both my xp and windows 7 machines. I modified the script to first check for the OS on the machine and then use the correct session id for that OS. Works perfectly for what I need to gather.
0
RobSampsonCommented:
No worries.  Are you saying that it's always session ID 2, even when someone is logged in at the console?  That seems odd....but you never know...

Thanks for the grade.

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
Server Hardware

From novice to tech pro — start learning today.