analitics

Pages

Thursday, May 23, 2019

Python 3.7.3 : Using the win32com - part 002.

Today I tested the win32com python module with python 3.7.3.
I'll show you two scripts I tested with this python module.
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_ClassicCOMClass")
for objItem in colItems:
    print("Component ID: " , objItem.ComponentId)
    print("Description: " , objItem.Description)
    print("Name: " , objItem.Name)
The result is something like this:
Name:  Shell Execute Hardware Event Handler
Component ID:  {FFC9F9AE-E87A-3252-8E25-B22423A40 }
Description:  System.ThreadStaticAttribute
Name:  System.ThreadStaticAttribute
Component ID:  {FFCDB781-D71C-4D10-BD5F-0492EAFFD }
Description:  PSFactoryBuffer
Name:  PSFactoryBuffer
Component ID:  {ffd90217-f7c2-4434-9ee1-6f1b530db }
Description:  XML Feed Moniker
Name:  XML Feed Moniker
Component ID:  {ffe1df5f-9f06-46d3-af27-f1fc10d63 }
Description:  HomeGroup CPL Advanced Settings Writer
Name:  HomeGroup CPL Advanced Settings Writer
Component ID:  {FFE2A43C-56B9-4bf5-9A79-CC6D42856 }
Description:  Windows Photo Viewer Image Verbs
Name:  Windows Photo Viewer Image Verbs
The following example contains this source code:
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_ComponentCategory")
for objItem in colItems:
    print("Category ID: " , objItem.CategoryId)
    print("Name: " , objItem.Name)
The result is something like this:
Name:  3D DirectTransform
Category ID:  {F0B7A1A1-9847-11CF-8F20-00805F2CD }
Name:  Active Scripting Engine
Category ID:  {F0B7A1A2-9847-11CF-8F20-00805F2CD }
Name:  Active Scripting Engine with Parsing
Category ID:  {F0B7A1A3-9847-11CF-8F20-00805F2CD }
Name:  Active Scripting Engine with Encoding