Information with WMI in Python.

Joined
Feb 25, 2023
Messages
1
Reaction score
0
I'm trying to list a system summary and a summary of the components like MutliMedia, Sound Device, Input, Networks, Port Storage with WMI and WIN32_classes so far I have come up with this solution:

Do I have to list them up al seperatly or can I iterate through them? It's hard to find the right WIN32_classes and Visual Studio Code isn't showing me the properties like Name or Caption with intellisense I wander if this is normal behaviour or Pycharm just works better and will show me the properties of the WIN32_classes (haven't tried it yet.).

import wmi
c = wmi.WMI()

# List Win32 classes:

# https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-provider

# How to get a list of system summary and components?


computer_systems = c.Win32_Computersystem()
componenten = c.WIN32_SystemDevices()
drivers = c.Win32_SystemDriver()
printJobs = c.Win32_PrintJob()
netwerkConnecties = c.Win32_NetworkAdapter()
runningTasks = c.Win32_Process()
services = c.Win32_Service()
startupPrograms = c.Win32_StartupCommand()


# print("System Summary: \n\n")
# for computer_system in computer_systems:
# print(computer_system.Name)

# print("Components: \n")
# for component in componenten:
# print(component.Name)

# independent this works:

print("Software Environment:\n\n")
print("Systeem Drivers: \n ")
for driver in drivers:
print(driver.Name)

print("\nPrintJob: \n")
for printJob in printJobs:
print(printJob.Name)

print("\nNetwerk connecties: \n")
for netwerkConnectie in netwerkConnecties:
print(netwerkConnectie.Name)

print("\nRunning Tasks: \n")
for runningTask in runningTasks:
print(runningTask.Name)

print("\nServices: \n")
for service in services:
print(service.Name)

print("\nStartup Programs: \n")
for startupProgram in startupPrograms:
print(startupProgram.Name)

I get information about some compenents but not everything I want like the system summary and a summary of components.
 
Joined
Mar 5, 2023
Messages
36
Reaction score
12
You can use WMI to retrieve a wide range of system information, including system summary and component information. Here's an example code that should get you started:


Python:
import wmi

c = wmi.WMI()

# Get system summary
system_summary = c.Win32_ComputerSystem()[0]
print("System Summary:")
print(f"  Name: {system_summary.Name}")
print(f"  Manufacturer: {system_summary.Manufacturer}")
print(f"  Model: {system_summary.Model}")
print(f"  Total Physical Memory: {system_summary.TotalPhysicalMemory}")

# Get multimedia devices
multimedia_devices = c.Win32_SoundDevice()
print("\nMultimedia Devices:")
for device in multimedia_devices:
    print(f"  {device.Caption}")

# Get input devices
input_devices = c.Win32_PointingDevice()
print("\nInput Devices:")
for device in input_devices:
    print(f"  {device.Caption}")

# Get network adapters
network_adapters = c.Win32_NetworkAdapterConfiguration(IPEnabled=True)
print("\nNetwork Adapters:")
for adapter in network_adapters:
    print(f"  {adapter.Description}")
    print(f"    IP Address: {adapter.IPAddress[0]}")

# Get storage devices
storage_devices = c.Win32_DiskDrive()
print("\nStorage Devices:")
for device in storage_devices:
    print(f"  {device.Caption}")

This code retrieves the system summary, multimedia devices, input devices, network adapters, and storage devices using the appropriate WMI classes. You can add more sections and classes to retrieve other information you need.

Hope this will do the trick for ya!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top