I don't know how to get the "default printer name" (default printer) in PYTHON.
The program below is a program that changes the "default printer" to a "different printer". → I want to get the current "default printer name"!
Thank you for your professor on how to obtain the "default printer name".
The program below is a program that changes the "default printer" to a "Microsoft Print to PDF" printer. (I'm hitting the command prompt from python)
Printer change program.py
import subprocess
cmd = 'rundll32.exe printui.dll,PrintUIEntry /y /n "Microsoft Print to PDF"'
returncode = subprocess.call(cmd)
There is a code for "Getting the printer name you normally use" on the net with VBS (URL: https://ekafp7.blogspot.com/2016/12/blog-post.html) Similarly, I arranged it with PYTHON as shown below, but an error appears on the 4th line. objClassSet = objService.ExecQuery("Select * From Win32_Printer") I'm not sure if the argument is bad, but I get an error.
Printer acquisition program used normally.py
import win32com.client
objLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objService = objLocator.ConnectServer
objClassSet = objService.ExecQuery("Select * From Win32_Printer")
for objClass in objClassSet:
if objClass.Default:
strName = objClass.Caption
print(strName)
Also, the list of printers was shown in the program below, but the "default printer name" does not appear. ..
Printer list program.py
import win32com.client
o = win32com.client.Dispatch("WScript.Network")
prlist = o.EnumPrinterConnections()
for pr in prlist:
print(pr)
Recommended Posts