/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (3)

Posted by: andler 18 years ago
Orange Belt
0
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
Posted by: WiseUser 18 years ago
Fourth Degree Brown Belt
0
If objDrives.Item(i) = sMYDRIVE Then

Remember that comparisons are case-sensitive... if "objDrives.Item(i)" is "I:", the above statement will be false.[;)]
Posted by: WiseUser 18 years ago
Fourth Degree Brown Belt
-1
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!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ