Code: Select all
VBSTART
Sub DefaultPrinter
Dim Text, Title, i, j, tmp, printer
Dim Network, oDevices
' Create a new Network object to access Network properties
Set Network = CreateObject("WScript.Network")
' Read all printers
Set oDevices = Network.EnumPrinterConnections
Text = "Available printers" & vbCRLF
For i = 0 To oDevices.Count-1 Step 2
j = i
Text = Text & (i / 2) & vbTab
Text = Text & oDevices(i) & vbTab & oDevices(i+1) & vbCRLF
Next
' Show all available printers and allow a user selection
tmp = InputBox (Text,"Set default printer",0)
printer = oDevices(tmp * 2) ' select printer name
' Set the default printer
Network.SetDefaultPrinter printer
MsgBox "Set Default printer to " & printer, _
vbOkonly + vbInformation, Title
Set Network = Nothing
End Sub
VBEND
VBRun>DefaultPrinter