Hi everyone,

Can any body help me in writing vbscript to check for the drive mapping.

Thanks,

Sanhivi

Answer Summary:
Option ExplicitDim strDriveLetterDim objShell, objNetworkDim CheckDrive, AlreadyConnected, intDrive strDriveLetter = "Z:" Set objShell = CreateObject("WScript.Shell") Set objNetwork = CreateObject("WScript.Network") Set CheckDrive = objNetwork.EnumNetworkDrives() On Error Resume NextAlreadyConnected = False For intDrive = 0 To CheckDrive.Count - 1 Step 2 If CheckDrive.Item(intDrive) =strDriveLetter Then AlreadyConnected =TrueNext If AlreadyConnected = True then objShell.PopUp "Drive " & strDriveLetter & _" is already connected" Else objShell.PopUp "Drive " & strDriveLetter & _" is not connected." End if WScript.Quit
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

3

Here is a quick way to achieve this through VBScript:

Option Explicit
Dim strDriveLetter
Dim objShell, objNetwork
Dim CheckDrive, AlreadyConnected, intDrive
strDriveLetter = "Z:"


Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()


On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter Then AlreadyConnected =True
Next


If AlreadyConnected = True then

objShell.PopUp "Drive " & strDriveLetter & _
" is already connected"
Else

objShell.PopUp "Drive " & strDriveLetter & _
" is not connected."
End if
WScript.Quit

Answered 05/17/2012 by: adilrathore
Fourth Degree Black Belt

Please log in to comment
Answer this question or Comment on this question for clarity