Script to check mounted network drive and remount it
Hi,
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 !
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
[ + ] Show comments
Answers (4)
Please log in to answer
Posted by:
anonymous_9363
16 years ago
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)
Next
Set colDrives = Nothing
Set objNetwork = Nothing
There is a collection of scripts which may help at http://www.computerperformance.co.uk/vbscript/index.htm
Posted by:
oxyi
16 years ago
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.
For
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.
next
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 !
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.
For
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.
next
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 !
Posted by:
anonymous_9363
16 years ago
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.
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.
Posted by:
oxyi
16 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.