Page 1 of 1 1
Topic Options
#192256 - 2009-02-13 06:15 PM script to read persistant drive mappings from registry
coder Offline
Fresh Scripter

Registered: 2009-01-14
Posts: 39
Does anyone have a script to read persistent drive mappings from the registry?

I want to(in script) note the current drive mappings before I remap them using the MapDrive Function.

Fomr what I can determine they are stored in "HKCU\Software\Microsoft\Network\Persistant" with subkeys being the drives.


Edited by coder (2009-02-13 06:27 PM)
Edit Reason: add reg key

Top
#192263 - 2009-02-13 06:35 PM Re: script to read persistant drive mappings from registry [Re: coder]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Look at EnumKey and EnumValue functions. Put a small test together from the examples and it will make sense. These return each of the keys or values from a registry path, one by one.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192265 - 2009-02-13 07:02 PM Re: script to read persistant drive mappings from registry [Re: Glenn Barnas]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
I think there is at least a couple of different UDFs that list out your network drives... one being EnumNetworkDrives: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=138356

However, I don't know if there is a way to know if the drives are persistent or not.
_________________________
(... better days ahead)

Top
#192270 - 2009-02-13 08:41 PM Re: script to read persistant drive mappings from registry [Re: Allen]
coder Offline
Fresh Scripter

Registered: 2009-01-14
Posts: 39
Allen: The only one I see is the one you pointed out. Is there any way to have it return just the persistent drives?
Top
#192271 - 2009-02-13 09:35 PM Re: script to read persistant drive mappings from registry [Re: coder]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
I just mashed this together using Kixomatic. See if it will get you going.
Break On
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
For each $objItem in $colItems
if $objItem.Persistent
"AccessMask: " + $objItem.AccessMask ?
"Caption: " + $objItem.Caption ?
"Comment: " + $objItem.Comment ?
"ConnectionState: " + $objItem.ConnectionState ?
"ConnectionType: " + $objItem.ConnectionType ?
"Description: " + $objItem.Description ?
"DisplayType: " + $objItem.DisplayType ?
"InstallDate: " + $objItem.InstallDate ?
"LocalName: " + $objItem.LocalName ?
"Name: " + $objItem.Name ?
"Persistent: " + $objItem.Persistent ?
"ProviderName: " + $objItem.ProviderName ?
"RemoteName: " + $objItem.RemoteName ?
"RemotePath: " + $objItem.RemotePath ?
"ResourceType: " + $objItem.ResourceType ?
"Status: " + $objItem.Status ?
"UserName: " + $objItem.UserName ?
?
endif
Next

_________________________
(... better days ahead)

Top
#192287 - 2009-02-14 07:53 PM Re: script to read persistant drive mappings from registry [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just to waste some time, I shall write it in this quick reply box...

 Code:
for $charcode=65 to 90
 $driveConnectedTo = readvalue("HKCU\Network\"+chr($charcode),"RemotePath")
 if instr($driveConnectedTo,"\\")
  ? "Drive " + chr($CharCode) + " is PERSISTENTLY connected to: " + $driveConnectedTo
 endif
next


just like the original poster suggested, the info is in the registry.
_________________________
!

download KiXnet

Top
#192298 - 2009-02-16 05:59 PM Re: script to read persistant drive mappings from registry [Re: Lonkero]
coder Offline
Fresh Scripter

Registered: 2009-01-14
Posts: 39
Thank you Lonkero.
I had already adapted the WMI script. I will now test and integrate yours into my larger script. My users are too sensitive to 30 to 40 second delays (imho).

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.057 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org