• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Finding Current User Network Drives in the Registry

J

James

#1
I want to write a pure vbs script to find out how many network drives a user
has mapped and then write the values of the drive letter (plus the unc path)
into a log file. The info lies in the registry at
HKEY_CURRENT_USER>Network. All the drive letters would be a sub folder of
the Network folder. For example if a user had their H: drive mapped to
their user directory that lived at "\\server name\users" then you would see
a sub folder under the Network folder labeled H and it would then have a Key
labeled "Remote Path" with a string value (szValue) set to \\server
name\users.

I need to be able to read the contents of the Network folder to see how may
subfolders it has. This will tell me how many mapped drives a user has. I
am not sure if it is possible to grab all the sub folders (and their labels)
but if I can, then I am thinking I can simply loop through them and get the
string values of their correcsponding keys and then write them to a log
file.

Any ideas if this can be done? If so, any help would be greatly
appreciated.

James
 
P

Pegasus [MVP]

#2
"James" <dontemailme@xxxxxx> wrote in message
news:Ok64FrCIKHA.4376@xxxxxx

>I want to write a pure vbs script to find out how many network drives a
>user has mapped and then write the values of the drive letter (plus the unc
>path) into a log file. The info lies in the registry at
>HKEY_CURRENT_USER>Network. All the drive letters would be a sub folder of
>the Network folder. For example if a user had their H: drive mapped to
>their user directory that lived at "\\server name\users" then you would see
>a sub folder under the Network folder labeled H and it would then have a
>Key labeled "Remote Path" with a string value (szValue) set to \\server
>name\users.
>
> I need to be able to read the contents of the Network folder to see how
> may subfolders it has. This will tell me how many mapped drives a user
> has. I am not sure if it is possible to grab all the sub folders (and
> their labels) but if I can, then I am thinking I can simply loop through
> them and get the string values of their correcsponding keys and then write
> them to a log file.
>
> Any ideas if this can be done? If so, any help would be greatly
> appreciated.
>
> James
The information you're after is directly available from the "net use"
command. It is also kept in
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2 but
probably not in a usable form.
 
J

James

#3
Thanks Pegasus...

I also found the following

strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
strKeyPath = "Network\"

objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
WScript.Echo "Subkeys under " _
& "HKEY_CURRENT_USER\Network"
For Each subkey In arrSubKeys
WScript.Echo subkey
Next

All I have to do now is for each subkey get the value and write it to a
file...

YIPEE!

James

"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:ua5vSMDIKHA.1248@xxxxxx

>
> "James" <dontemailme@xxxxxx> wrote in message
> news:Ok64FrCIKHA.4376@xxxxxx

>>I want to write a pure vbs script to find out how many network drives a
>>user has mapped and then write the values of the drive letter (plus the
>>unc path) into a log file. The info lies in the registry at
>>HKEY_CURRENT_USER>Network. All the drive letters would be a sub folder of
>>the Network folder. For example if a user had their H: drive mapped to
>>their user directory that lived at "\\server name\users" then you would
>>see a sub folder under the Network folder labeled H and it would then have
>>a Key labeled "Remote Path" with a string value (szValue) set to \\server
>>name\users.
>>
>> I need to be able to read the contents of the Network folder to see how
>> may subfolders it has. This will tell me how many mapped drives a user
>> has. I am not sure if it is possible to grab all the sub folders (and
>> their labels) but if I can, then I am thinking I can simply loop through
>> them and get the string values of their correcsponding keys and then
>> write them to a log file.
>>
>> Any ideas if this can be done? If so, any help would be greatly
>> appreciated.
>>
>> James
>
> The information you're after is directly available from the "net use"
> command. It is also kept in
> HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2 but
> probably not in a usable form.
>
 
P

Pegasus [MVP]

#4
"James" <dontemailme@xxxxxx> wrote in message
news:%23hmR1RDIKHA.3632@xxxxxx

> Thanks Pegasus...
>
> I also found the following
>
> strComputer = "."
> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> strComputer & "\root\default:StdRegProv")
> strKeyPath = "Network\"
>
> objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
> WScript.Echo "Subkeys under " _
> & "HKEY_CURRENT_USER\Network"
> For Each subkey In arrSubKeys
> WScript.Echo subkey
> Next
>
> All I have to do now is for each subkey get the value and write it to a
> file...
>
> YIPEE!
>
> James
This is the same idea as in your initial post. On my WinXP machine it won't
return any mapped share information. I recommend you test your script on a
few machines before spending much more time on it.
 
J

James

#5
I did....ran it on several machines running WinXP Pro on our network...its
working for me...


"Pegasus [MVP]" <news@xxxxxx> wrote in message
news:en49aaDIKHA.4708@xxxxxx

>
> "James" <dontemailme@xxxxxx> wrote in message
> news:%23hmR1RDIKHA.3632@xxxxxx

>> Thanks Pegasus...
>>
>> I also found the following
>>
>> strComputer = "."
>> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
>> strComputer & "\root\default:StdRegProv")
>> strKeyPath = "Network\"
>>
>> objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
>> WScript.Echo "Subkeys under " _
>> & "HKEY_CURRENT_USER\Network"
>> For Each subkey In arrSubKeys
>> WScript.Echo subkey
>> Next
>>
>> All I have to do now is for each subkey get the value and write it to a
>> file...
>>
>> YIPEE!
>>
>> James
>
> This is the same idea as in your initial post. On my WinXP machine it
> won't return any mapped share information. I recommend you test your
> script on a few machines before spending much more time on it.
>
 
E
#6
Why hack the info out of the registry? Just use the proper method. MS even
provides a sample script.
http://msdn.microsoft.com/en-us/library/t9zt39at(VS.85).aspx

"James" <dontemailme@xxxxxx> wrote in message
news:eo8VaAEIKHA.4708@xxxxxx

>I did....ran it on several machines running WinXP Pro on our network...its
>working for me...
>
>
> "Pegasus [MVP]" <news@xxxxxx> wrote in message
> news:en49aaDIKHA.4708@xxxxxx

>>
>> "James" <dontemailme@xxxxxx> wrote in message
>> news:%23hmR1RDIKHA.3632@xxxxxx

>>> Thanks Pegasus...
>>>
>>> I also found the following
>>>
>>> strComputer = "."
>>> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
>>> strComputer & "\root\default:StdRegProv")
>>> strKeyPath = "Network\"
>>>
>>> objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
>>> WScript.Echo "Subkeys under " _
>>> & "HKEY_CURRENT_USER\Network"
>>> For Each subkey In arrSubKeys
>>> WScript.Echo subkey
>>> Next
>>>
>>> All I have to do now is for each subkey get the value and write it to a
>>> file...
>>>
>>> YIPEE!
>>>
>>> James
>>
>> This is the same idea as in your initial post. On my WinXP machine it
>> won't return any mapped share information. I recommend you test your
>> script on a few machines before spending much more time on it.
>>
>
>
 
J

James

#7
LMAO...that is good. I found the info from MS about the registry and just
ran with it (below)...both work, so it doesn't really matter to me which one
to use...but now I have another method I can use, plus the sample you
provided snags the printer info too if I ever need it...thanks a ton!

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("PROCESS")

strHomePath = WshSysEnv("HOMEPATH")
strDest = "c:" & strHomePath & "\desktop"

'Backup file of mapped drive paths
strKeyPath = "Network\"
strKeyName = "RemotePath"
objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
Set MyFile = filesys.CreateTextFile(strDest & "MappedDrives.txt", True)

For Each subkey In arrSubKeys
objReg.GetSTRINGValue HKEY_CURRENT_USER,strKeyPath & "\" &
subkey,strKeyName,szValue
intLength = Len(szValue)-1
strUncPath = Right(szValue, intLength)
MyFile.WriteLine subkey & ":" & strUncPath
Next
MyFile.Close

James


"Eric" <someone@xxxxxx> wrote in message
news:%23VdxzjMIKHA.4708@xxxxxx

> Why hack the info out of the registry? Just use the proper method. MS
> even provides a sample script.
> http://msdn.microsoft.com/en-us/library/t9zt39at(VS.85).aspx
>
> "James" <dontemailme@xxxxxx> wrote in message
> news:eo8VaAEIKHA.4708@xxxxxx

>>I did....ran it on several machines running WinXP Pro on our network...its
>>working for me...
>>
>>
>> "Pegasus [MVP]" <news@xxxxxx> wrote in message
>> news:en49aaDIKHA.4708@xxxxxx

>>>
>>> "James" <dontemailme@xxxxxx> wrote in message
>>> news:%23hmR1RDIKHA.3632@xxxxxx
>>>> Thanks Pegasus...
>>>>
>>>> I also found the following
>>>>
>>>> strComputer = "."
>>>> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
>>>> strComputer & "\root\default:StdRegProv")
>>>> strKeyPath = "Network\"
>>>>
>>>> objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
>>>> WScript.Echo "Subkeys under " _
>>>> & "HKEY_CURRENT_USER\Network"
>>>> For Each subkey In arrSubKeys
>>>> WScript.Echo subkey
>>>> Next
>>>>
>>>> All I have to do now is for each subkey get the value and write it to a
>>>> file...
>>>>
>>>> YIPEE!
>>>>
>>>> James
>>>
>>> This is the same idea as in your initial post. On my WinXP machine it
>>> won't return any mapped share information. I recommend you test your
>>> script on a few machines before spending much more time on it.
>>>
>>
>>
>
>