Python Forum
New to Python: Looking to run WMI/WMIC Commands from Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Python: Looking to run WMI/WMIC Commands from Python
#1
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?
Reply
#2
The documentation on this site has example code: https://pypi.org/project/WMI/
you can get this package with:
pip install WMI
Reply
#3
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!
Reply
#4
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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending string commands from Python to a bluetooth device Rovelin 13 9,282 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  Python library for win32 console commands eldiener 3 3,384 Aug-24-2021, 10:28 PM
Last Post: bowlofred
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,235 May-18-2021, 06:31 AM
Last Post: Skaperen
  Raspi Commands via Python (VS Code) Script AS4188 5 2,740 Oct-21-2020, 03:49 PM
Last Post: AS4188
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 2,984 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS
  Questions re: my first python app (GUI, cross-platform, admin/root-level commands)? DonnyBahama 0 1,702 Feb-27-2020, 08:14 PM
Last Post: DonnyBahama
  Python script dioesn`t run all commands exploit123 5 2,851 Sep-25-2019, 03:15 PM
Last Post: snippsat
  Help with run commands from a python script necoxiro 6 4,562 Apr-25-2018, 03:03 AM
Last Post: Skaperen
  import commands modules not working in python 3.6.0 bmohanraj91 2 17,533 May-01-2017, 10:59 AM
Last Post: bmohanraj91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020