I've been looking for a script that can detect what network drive were mounted, then remount the same drive again.
Is such thing exist ? I know it need a while loop chceking each pre-mounted network drive, and save the driveletter and path,
then remount it right away, then it will go to the next one, but I am kinda stuck as how would I be able to do that part,
does VB allow me to read the network path and letter and save it and use it right away ?

thanks !
0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


User-defined network drive definitions are stored beneath HKCU\Network, with the drive letter as the key. That key's RemotePath value contains the server name/share of the target. If that's not what you're after, does this help as a starting point:
Option Explicit

Dim objNetwork
Dim colDrives
Dim intCounter

On Error Resume Next

Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives

For intCounter = 0 to colDrives.Count-1 Step 1
'objNetwork.RemoveNetworkDrive colDrives.Item(intCounter)
WScript.Echo colDrives.Item(intCounter)

Set colDrives = Nothing
Set objNetwork = Nothing
There is a collection of scripts which may help at http://www.computerperformance.co.uk/vbscript/index.htm
Answered 05/06/2008 by: VBScab
Red Belt

Please log in to comment
Sorry, I am still a newbie at VBscript, but judging from the code,

you use a loop to go thru the network drives and removing it, then I am kind of lost.

Also, thanks for the tips on the HKCU\Network, my idea of the script is like the following.

a network drive is detected, store the driveletter and remotepath to each own value.
unmount the current network drive
Re-mount the network drive thst just unmount by using the stored value in driveletter and remotepath.

The part I can't quite figure out is how do you read the current driveletter and remotepath of the network drive you are removing and store the value for a the remount later on, that part just beats me.

In case you are wondering why I am doing this, because I just did a fileserver migration to the DFS, and all the current mounted drive can not access the file server unless I "refresh" them, which is remounting all the current drive :)

Thanks again for the reply and help !
Answered 05/06/2008 by: oxyi
Yellow Belt

Please log in to comment
OK, there's a bit of work involved, mainly because you need to enumerate through registry keys, something which native VB Script cannot do. There is a registry class knocking about which, IIRC, is called cRegistry.VBS or cRegistry.cls. That has an EnumKeysAndValues method which populates an array (or it might be a collection...can't remember) with the keys and all values contained within that key. It's pretty straightforward to use. Don't be put off by use of the word 'class': all you do is add the code to the bottom of your script and use the properties and methods once you've created an object which uses that class. It's a lot simpler to just do it than it sounds.

Alternatively, you could still use the code I posted as a base and use a registry call to get the 'RemotePath' value's data, populating an array or collection with that data, using the drive letter as the index or key.
Answered 05/06/2008 by: VBScab
Red Belt

Please log in to comment
sounds like a plan, I will try to use your code as a base and write my script on top of that.
I will post back once I got something solid.

Thanks again !
Answered 05/06/2008 by: oxyi
Yellow Belt

Please log in to comment