WshNetwork.EnumPrinterConnections
Enumerate printer connections
Syntax
myObject.EnumPrinterConnections
Example:
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
Next
https://ss64.com/vb/enumprinterconnections.html
WshNetwork.SetDefaultPrinter
Assign a remote printer the role Default Printer.
Syntax WshNetwork.SetDefaultPrinter(strPrinterName) Arguments strPrinterName : The remote printer's UNC name. Examples: 'Set the Default Printer to \\research\library1 Dim WshNetwork Set WshNetwork = CreateObject("WScript.Network") WshNetwork.SetDefaultPrinter "\\research\library1" ' Connect to \\research\library1 and set it as the default. Set PrinterPath = "\\research\library1" Set WshNetwork = WScript.CreateObject("WScript.Network") Set rc = WshNetwork.AddWindowsPrinterConnection(PrinterPath) If Not rc then WScript.Echo("Printer Connection Failed!") End If WshNetwork.SetDefaultPrinter PrinterPath
This method fails when using a DOS-based printer connection.
You cannot use the SetDefaultPrinter method find out the name of the current default printer.
https://ss64.com/vb/setdefaultprinter.html