LFC4Llife
asked on
Verify/Delete multiple drive and printer mapping in VBScript
I'm in the process of configuring my first VBScript and reached an area in which I can map/verify a single drive and printer mapping. However i now need to perform the same function using multiple drive and printer mappings. any assist appreciated... 24hrs into vb scripting 101 ;)
see below for an excerpt of what i was able to put together using various samples...
' Start of Script
'Initialize variables
Option Explicit
Dim strDriveLetter1, strRemotePath1; strPrinter
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
' Set variables.
strDriveLetter1 = "P:"
strRemotePath1 = "\\FileServer1\FilePath1"
strPrinter1 = "\\PrintServer1\Printer1"
Set objShell = CreateObject("WScript.Shel l")
Set objNetwork = CreateObject("WScript.Netw ork")
Set CheckDrive = objNetwork.EnumNetworkDriv es()
' Compare drive mappings
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter1 _
Then AlreadyConnected =True
Next
' Check drive mappings and see if the drive is already mapped.
' If yes then disconnects
If AlreadyConnected = True then
objNetwork.RemoveNetworkDr ive strDriveLetter1
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
' Verify drive mappings
objShell.PopUp "Drive " & strDriveLetter1 & _
"Disconnected, then connected successfully."
Else
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objShell.PopUp "Drive " & strDriveLetter1 & _
" connected successfully." End if
' Map network printers
Set objNetwork = CreateObject("WScript.Netw ork")
objNetwork.AddWindowsPrint erConnecti on strPrinter
WScript.Quit
' End of Script
see below for an excerpt of what i was able to put together using various samples...
' Start of Script
'Initialize variables
Option Explicit
Dim strDriveLetter1, strRemotePath1; strPrinter
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
' Set variables.
strDriveLetter1 = "P:"
strRemotePath1 = "\\FileServer1\FilePath1"
strPrinter1 = "\\PrintServer1\Printer1"
Set objShell = CreateObject("WScript.Shel
Set objNetwork = CreateObject("WScript.Netw
Set CheckDrive = objNetwork.EnumNetworkDriv
' Compare drive mappings
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter1 _
Then AlreadyConnected =True
Next
' Check drive mappings and see if the drive is already mapped.
' If yes then disconnects
If AlreadyConnected = True then
objNetwork.RemoveNetworkDr
objNetwork.MapNetworkDrive
' Verify drive mappings
objShell.PopUp "Drive " & strDriveLetter1 & _
"Disconnected, then connected successfully."
Else
objNetwork.MapNetworkDrive
objShell.PopUp "Drive " & strDriveLetter1 & _
" connected successfully." End if
' Map network printers
Set objNetwork = CreateObject("WScript.Netw
objNetwork.AddWindowsPrint
WScript.Quit
' End of Script
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks works like a charm...
No problem . Thanks for the grade.
Regards,
Rob.
Regards,
Rob.
ASKER