CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddPrinterConnection Port, RemotePath
End Sub
These subroutines remove the mapping for previously mapped drive letters
and network printers, respectively:
Sub UnMapNetDrive(DriveLetter)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
WShNetwork.RemoveNetworkDrive DriveLetter
End Sub
Sub UnMapNetPrinter(Port)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection Port
End Sub
This next script serves as an example for these subroutines. It??™s used to map
a network drive if it??™s not already mapped, or to disconnect a currently
mapped drive. The AlreadyMapped, MapNetDrive, and UnMapNetDrive routines
are required.
Object References | 533
Scripting and
Automation
DriveLetter = "N:"
RemotePath = "\\server\c"
If AlreadyMapped(DriveLetter) then
Call UnMapNetDrive(DriveLetter)
Msgbox "Drive " & DriveLetter & " disconnected."
Else
Call MapNetDrive(DriveLetter, RemotePath)
Msgbox "Drive " & DriveLetter & " connected."
End if
This script requires no user interaction once it has been executed and displays
only a single confirmation message when it??™s done. The first two lines
contain the drive letter and network path to be mapped together. Then, the
AlreadyMapped function is used to determine whether the drive mapping
already exists.
Pages:
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741