Windows Vista Forums

Finding Current User Network Drives in the Registry

  1. #1


    James Guest

    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

  2. #2


    Pegasus [MVP] Guest

    Re: Finding Current User Network Drives in the Registry


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



      My System SpecsSystem Spec

  3. #3


    James Guest

    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

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


      My System SpecsSystem Spec

  4. #4


    Pegasus [MVP] Guest

    Re: Finding Current User Network Drives in the Registry


    "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

  5. #5


    James Guest

    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

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

  6. #6


    Eric Guest

    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

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


      My System SpecsSystem Spec

  7. #7


    James Guest

    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

    > 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

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


      My System SpecsSystem Spec

Finding Current User Network Drives in the Registry

Similar Threads
Thread Forum
Vista not finding home network after router switched on/off by user.
As the title says. Its a Vaio laptop, running Vista Home premium (not sp1 yet just about to install after factory reset). Wired network. Home...
Vista General
My documents messed up, need help finding registry values!!
Okay, this is the situation, il keep it short. I changed the target path for my documents on the start menu ( location tab ) Tried doing it...
Vista file management
One system finding old but not current shares on another
I've got a desktop running Vista Home Professional and a laptop running Vista Business. The desktop machine can find and properly access all shared...
Vista networking & sharing
Finding and removing values in registry subkeys
I have been directed by Microsoft CSS to follow the instructions in KB300956 "How to manually rebuild Performance Counter Library values" on a...
PowerShell
finding removable drives
I am new to windows vista. I am using an HDD drive enclosure. It is connected to my usb. When I turned the power on, it says "new hardware" found...
Vista hardware & devices
Move Vista from current drive to RAID drives?
Hi All: I currently have Vista installed on a Sata drive and want to move it to 2 new SataII drives in a Raid0 array. I used an F6 floppy to...
Vista installation & setup
finding the logged on user (user name) with powershell using WMI?
whats a good way of finding out the currently logged in user of a particular machine? i do get-WmiObject -computer . Win32_LoggedOnUser but...
PowerShell