Python Forum

Full Version: New to Python: Looking to run WMI/WMIC Commands from Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It would appear I need to import some modules in my Python script to accomplish this but so far no luck.

I also downloaded and installed a WMIC for Python installer I found, not sure if it was needed.

I'd like to be able to run WMI/WMIC commands from my script, such as. WMIC bios

Any hints on how I might accomplish this?
The documentation on this site has example code: https://pypi.org/project/WMI/
you can get this package with:
pip install WMI
I will dive into this more. I did do the Windows install from that site already. I closed everything and restarted. I've tried running import WMI and using WMIC commands in the Python terminal and through PyCharm and nothing but errors. I'm obviously missing something. Hey, but I can print "Hello" just fine!
If you don't want to use WMI module as it's a bit messy, you could in theory start using 'wmic.exe' utility over subprocess library in python; (depends on how heavily you will be using WMI).

Example use:
from subprocess import getoutput as go
But you would need to do a bit of string manipulation afterwards, depending on how precise the query is going to be;
go('wmic /node:127.0.0.1 process list brief')