detecting a mapped drive (server) and replacing it

F

Fred

Hello folks,

We are in the process of changing the servers that many of our users
currently have mapped drives to file shares...Is there anyway to have a
login script (or any other script for that matter) detect the server name of
the mapped resource and re-map that drive to another server? Is there anyway
to do this by group name? Or someway through an Ou?

Thanks in advance for the help!
 
B

Bart Denison[MSFT]

You could do something like this this in a .vbs script and run it under
cscript:

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oNET = CreateObject("WScript.Network")
Set oNetDrives = oNET.EnumNetworkDrives
For i=0 to oNetDrives.Count -1 step 2
if oNetDrives.Item(i)="" then
' This removes network connections not attached to a drive
letter
oNet.RemoveNetworkDrive oNetDrives.Item(i+1), TRUE, TRUE
else
' This removes network conenctions that ARE mapped to a drive
letter
oNET.RemoveNetworkDrive oNetDrives.Item(i), TRUE, TRUE
end if
Next

NewDriveLetter = ""
'
' Iterate drives to find an available letter
' Skip A, B, and C since A & B are traditioanlly floppy, and C is the
boot drive
'
For I = ASC("D") to ASC("Z") step 1
If not oFSO.DriveExists(CHR(I)) then
NewDriveLetter = Chr(I) & ":"
Exit For
End If
Next
oNET.MapNetworkDrive NewDriveLetter, UNCPath, ,[UserName], [Password]
If not oFSO.DriveExists(NewDriveLetter) then
ErrorMsg = "Error - unable to map drive to " & NewDriveLetter & "to "
& TestShare
ErrorMsg = ErrorMsg & " using specified credentials. Please enter
valid credentials"
WScript.Echo ErrorMsg
End If

It's not necessarily the cleanest code, but it iterates existing
connections, deltes them, and then finds the next available drive eltter and
connects some server and share to that drive letter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top