I have a basic VB script that maps users drives but now need to combine it with one that maps printers and I'm not sure how? Could someone please help me out with this?
This is me trying to put the two together but probably completely wrong. Per the script the On Error Resume Next is important for the Printer mapping part but I read that is non-global so I'm not sure where it should go.
Code:
'Map Drive
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath
strDriveLetter = "s:"
strRemotePath = "\\server\files"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
WScript.Quit
Code:
' Script to add printers during user logon
On Error resume Next ' ver important otherwise users will get errors on subsequent reconnections
' Create the variable to hold printer connections
Dim Our_Printers
' Create variables for each printer string
' You can create as many as you like here
Dim Printer_1, Printer_2
' Initialise our printers
Printer_1 = "\\print-server\printer_1"
Printer_2 = "\\print-server\printer_2"
' Initialise the printer connections object
Set Our_Printers = CreateObject("WScript.Network")
' Connect each of our printers
Our_Printers.AddWindowsPrinterConnection Printer_1
Our_Printers.AddWindowsPrinterConnection Printer_2
WScript.Quit
This is me trying to put the two together but probably completely wrong. Per the script the On Error Resume Next is important for the Printer mapping part but I read that is non-global so I'm not sure where it should go.
Code:
Option Explicit
On Error resume Next
Dim objNetwork, strDriveLetter, strRemotePath
Dim objOur_Printers, strPrinter_1, strPrinter_2
strDriveLetter = "s:"
strRemotePath = "\\server\files"
strPrinter_1 = "\\print-server\printer_1"
strPrinter_2 = "\\print-server\printer_2"
Set objNetwork = CreateObject("WScript.Network")
Set objOur_Printers = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
objOur_Printers.AddWindowsPrinterConnection Printer_1
objOur_Printers.AddWindowsPrinterConnection Printer_2
WScript.Quit