How to get the UNC path of a driveletter using VBScript?
Hi all
I have an application that needs to have a certain driveletter mapped to a certain UNC path.
Map I:\ to \\<servername>\<foldername>
In most cases the users have this driveletter mapped to the correct source. But if they don't I want to map it.
I need a script that check
If I: is mapped
If I: is mapped, check if it is mapped to the correct server and folder.
If I: is mapped to the correct - then OK
If I: is mapped, but not to the correct server and folder - disconnect drive and connect to correct server and folder
If I: is not mapped - connect to correct server and folder.
I have found a script for disconnecting and connecting drives so this should be OK.
What I haven't been able to solve so far is how to resolve the UNC of a mapped drive and run a check against this string.
Can anyone help me with this?
br
andler
I have an application that needs to have a certain driveletter mapped to a certain UNC path.
Map I:\ to \\<servername>\<foldername>
In most cases the users have this driveletter mapped to the correct source. But if they don't I want to map it.
I need a script that check
If I: is mapped
If I: is mapped, check if it is mapped to the correct server and folder.
If I: is mapped to the correct - then OK
If I: is mapped, but not to the correct server and folder - disconnect drive and connect to correct server and folder
If I: is not mapped - connect to correct server and folder.
I have found a script for disconnecting and connecting drives so this should be OK.
What I haven't been able to solve so far is how to resolve the UNC of a mapped drive and run a check against this string.
Can anyone help me with this?
br
andler
0 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
andler
19 years ago
Hi WiseUser
Thanks for guiding me.
I had to make some small changes to your script in order to make it work.
I guess thats part of your idea, make me think.
If you have any comments to my changes please let me know.
br
andler
***********************************************
On Error Resume Next
Dim objDrives, fldr, i
Const sMYDRIVE = "i:"
Const sMYUNC = "\\hank\info"
Set objDrives = wshNetwork.EnumNetworkDrives
For i = 0 to (objDrives.Count - 1) Step 2
If objDrives.Item(i) = sMYDRIVE Then
fldr = LCase(objDrives.Item(i+1))
If sMYUNC <> fldr Then
wshNetwork.RemoveNetworkDrive sMYDRIVE, True
wshNetwork.MapNetworkDrive sMYDRIVE, sMYUNC
End If
Else
wshNetwork.RemoveNetworkDrive sMYDRIVE, True
wshNetwork.MapNetworkDrive sMYDRIVE, sMYUNC
End If
Next
Thanks for guiding me.
I had to make some small changes to your script in order to make it work.
I guess thats part of your idea, make me think.
If you have any comments to my changes please let me know.
br
andler
***********************************************
On Error Resume Next
Dim objDrives, fldr, i
Const sMYDRIVE = "i:"
Const sMYUNC = "\\hank\info"
Set objDrives = wshNetwork.EnumNetworkDrives
For i = 0 to (objDrives.Count - 1) Step 2
If objDrives.Item(i) = sMYDRIVE Then
fldr = LCase(objDrives.Item(i+1))
If sMYUNC <> fldr Then
wshNetwork.RemoveNetworkDrive sMYDRIVE, True
wshNetwork.MapNetworkDrive sMYDRIVE, sMYUNC
End If
Else
wshNetwork.RemoveNetworkDrive sMYDRIVE, True
wshNetwork.MapNetworkDrive sMYDRIVE, sMYUNC
End If
Next
Posted by:
WiseUser
19 years ago
Posted by:
WiseUser
19 years ago
Something like this?
On Error Resume Next
Const sMYDRIVE = "J:"
Const sMYUNC = "\\127.0.0.1\d$"
Set oWSN = CreateObject("WScript.Network")
Set oDrives = oWSN.EnumNetworkDrives
For i = 0 to oDrives.Count - 1 Step 2
If oDrives.Item(i) = sMYDRIVE Then sUNC = LCase(oDrives.Item(i+1))
Next
If sUNC = LCase(sMYUNC) Then
Msgbox "OK"
Else
oWSN.RemoveNetworkDrive sMYDRIVE, True
oWSN.MapNetworkDrive sMYDRIVE, sMYUNC
End If
Set oDrives = Nothing
Set oWSN = Nothing
Please note that I haven't tested this... I've no idea whether it'll work!
Const sMYDRIVE = "J:"
Const sMYUNC = "\\127.0.0.1\d$"
Set oWSN = CreateObject("WScript.Network")
Set oDrives = oWSN.EnumNetworkDrives
For i = 0 to oDrives.Count - 1 Step 2
If oDrives.Item(i) = sMYDRIVE Then sUNC = LCase(oDrives.Item(i+1))
Next
If sUNC = LCase(sMYUNC) Then
Msgbox "OK"
Else
oWSN.RemoveNetworkDrive sMYDRIVE, True
oWSN.MapNetworkDrive sMYDRIVE, sMYUNC
End If
Set oDrives = Nothing
Set oWSN = Nothing
Please note that I haven't tested this... I've no idea whether it'll work!
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.