/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (4)

Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
Have you tried the scripts that are provided by MS in your "System32" folder?

"prnmngr.vbs" may be the one you want?
Posted by: Byoung4now 19 years ago
Senior Yellow Belt
0
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
Posted by: Gowri 16 years ago
Yellow Belt
0
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
Posted by: Gowri 16 years ago
Yellow Belt
0
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ