Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Finding Current User Network Drives in the Registry

Reply
 
Old 08-18-2009   #1 (permalink)
James


 
 

Finding Current User Network Drives in the Registry

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



My System SpecsSystem Spec
Old 08-18-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Finding Current User Network Drives in the Registry


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

>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.


My System SpecsSystem Spec
Old 08-18-2009   #3 (permalink)
James


 
 

Re: Finding Current User Network Drives in the Registry

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
Quote:

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

>>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.
>

My System SpecsSystem Spec
Old 08-18-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Finding Current User Network Drives in the Registry


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

> 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.


My System SpecsSystem Spec
Old 08-18-2009   #5 (permalink)
James


 
 

Re: Finding Current User Network Drives in the Registry

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
Quote:

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

>> 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.
>

My System SpecsSystem Spec
Old 08-19-2009   #6 (permalink)
Eric


 
 

Re: Finding Current User Network Drives in the Registry

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/libr...at(VS.85).aspx

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

>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
Quote:

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

>>> 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.
>>
>
>

My System SpecsSystem Spec
Old 08-19-2009   #7 (permalink)
James


 
 

Re: Finding Current User Network Drives in the Registry

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
Quote:

> 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/libr...at(VS.85).aspx
>
> "James" <dontemailme@xxxxxx> wrote in message
> news:eo8VaAEIKHA.4708@xxxxxx
Quote:

>>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
Quote:

>>>
>>> "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.
>>>
>>
>>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Vista not finding home network after router switched on/off by user. Vista General
My documents messed up, need help finding registry values!! Vista file management
One system finding old but not current shares on another Vista networking & sharing
Finding and removing values in registry subkeys PowerShell
finding removable drives Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46