Need VB Script to check whether the given drive is mapped or not.
Hi everyone,
Can any body help me in writing vbscript to check for the drive mapping.
Thanks,
Sanhivi
Answers (1)
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
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