Search This Blog

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, December 30, 2019

Using WMI in Python

Using WMI in Python

Two steps 
  1. Install pywin32 to support wmi commands 
  2. import wmi in python code

INSTALL PYWIIN32
  1. Open Python Terminal 
  2. Type pip install pywin32 and press enter. This will install pywin32
IMPORT WMI PYTHON

Like anyother import command you just need to use import wmi. Below is the sample code which get the list of services that is in stopped state (not running )

import wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
  if s.State == 'Stopped':
    print(s.Caption, s.State)

Wednesday, May 4, 2016

How to convert Python script file to Executable (.exe) file

1) Create a setup.py file and put in the same directory as of the .py file you want to convert.

2)Copy paste the following lines in the setup.py and do change the "filename.py" into the filename you specified.

from cx_Freeze import setup, Executable
setup(
    name="GUI PROGRAM",
    version="0.1",
    description="MyEXE",
    executables=[Executable("filename.py", base="Win32GUI")],
    )
3) Run the setup.py "$python setup.py build"

4)A new directory will be there there called "build". Inside it you will get your .exe file to be ready to launced directly. (Make sure you copy paste the images files and other external files into the build directory)