/build/static/layout/Breadcrumb_cap_w.png

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


0 Comments   [ + ] Show comments

Answers (1)

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
Posted by: adilrathore 12 years ago
4th Degree Black Belt
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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
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