Vbscript - Finding out a default printer
Hi All,
I have been searching for some code, with little success i may be just not searching right or not in the right place, but basically i just want some code to get thte current default printer of a machine, save it in script then call it later on in the script.
Im trying to make some vbscript that basically, maps a drive, ssaves the default printer, adds a printer and changes it to to default then loads an app, then when app closes, it removes network drive, and removes printer and sets default back to the original.
Possible?
Cheers,
Ry
I have been searching for some code, with little success i may be just not searching right or not in the right place, but basically i just want some code to get thte current default printer of a machine, save it in script then call it later on in the script.
Im trying to make some vbscript that basically, maps a drive, ssaves the default printer, adds a printer and changes it to to default then loads an app, then when app closes, it removes network drive, and removes printer and sets default back to the original.
Possible?
Cheers,
Ry
0 Comments
[ + ] Show comments
Answers (4)
Please log in to answer
Posted by:
WiseUser
19 years ago
Posted by:
Byoung4now
19 years ago
Give this a try. More than you need but you get the idea.
Google Scriptomatic. Cool toy with lots of uses.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Default: " & objItem.Default
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "Local: " & objItem.Local
Wscript.Echo "Location: " & objItem.Location
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Network: " & objItem.Network
Wscript.Echo "PortName: " & objItem.PortName
Wscript.Echo "ServerName: " & objItem.ServerName
Wscript.Echo "SystemName: " & objItem.SystemName
Next
Google Scriptomatic. Cool toy with lots of uses.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Default: " & objItem.Default
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "Local: " & objItem.Local
Wscript.Echo "Location: " & objItem.Location
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Network: " & objItem.Network
Wscript.Echo "PortName: " & objItem.PortName
Wscript.Echo "ServerName: " & objItem.ServerName
Wscript.Echo "SystemName: " & objItem.SystemName
Next
Posted by:
Gowri
16 years ago
Hi,
Use below script for set the printer as default printer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'HP Color LaserJet 4700 PCL 6'")
For Each objPrinter in colInstalledPrinters
objPrinter.SetDefaultPrinter()
Next
Use below script for set the printer as default printer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'HP Color LaserJet 4700 PCL 6'")
For Each objPrinter in colInstalledPrinters
objPrinter.SetDefaultPrinter()
Next
Posted by:
Gowri
16 years ago
Hi,
You can use below script for finding out the default printer using printer properties.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where Default = 'True'")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Next
You can use below script for finding out the default printer using printer properties.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where Default = 'True'")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Next
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.