python I don't know how to get the printer name that I usually use.

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

python I don't know how to get the printer name that I usually use.
I didn't know how to use the [python] for statement
How to get the variable name itself in python
How to get the Python version
I don't know how to get query parameters on GAE / P
How to use the C library in Python
[Algorithm x Python] How to use the list
How to get the files in the [Python] folder
[Python] I tried to get the type name as a string from the type function
I want to get the file name, line number, and function name in Python 3.4
How to get the number of digits in Python
I tried to summarize how to use matplotlib of python
How to know the current directory in Python in Blender
How to use the Raspberry Pi relay module Python
I wanted to use the Python library from MATLAB
[Python] How to use the graph creation library Altair
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
I tried to summarize how to use pandas in python
[Introduction to Udemy Python3 + Application] 30. How to use the set
How to use the model learned in Lobe in Python
I felt that I ported the Python code to C ++ 98.
I want to use the R dataset in python
I use python but I don't know the class well, so I will do a tutorial
python3: How to use bottle (2)
How to use the generator
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Python] How to use input ()
How to use the decorator
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
I tried to simulate how the infection spreads with Python
[python] How to use the library Matplotlib for drawing graphs
How to use the __call__ method in a Python class
[Hyperledger Iroha] Notes on how to use the Python SDK
I tried "How to get a method decorated in Python"
[Python] I want to use the -h option with argparse
How to get the last (last) value in a list in Python
I want to know the features of Python and pip
How to get into the python development environment with Vagrant
[Introduction to Python] How to get data with the listdir function
I tried to summarize how to use the EPEL repository again
If you don't know it, it's dangerous. Carefully explain how to use the xargs command
Python: How to use async with
How to use the zip function
How to use the optparse module
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
How to get started with Python
[Python] How to import the library
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python