How to get win32 COM objects e.g., to find hardware details


I’d like to find out some hardware details on Windows. This is straightforward in Python:

import win32com.client
obj = win32com.client.GetObject('winmgmts:Win32_Processor')
# ... get the details ...

But searching for getobject in the winapi crate doesn’t produce any results, so I don’t know if it is supported.
There’s also a com_rs crate, but it hasn’t been updated in more than a year and doesn’t have any examples.

Does anyone have some example code that would get me started?


In Rust working with COM is pretty similar to working with COM in C++. First you’d need to have the COM interface definitions. If winapi doesn’t have the COM interfaces you’ll be using then you’ll have to bind to the interface yourself using the RIDL! macro from winapi. Then you have to figure out what function to call to instantiate an instance of that interface. Typically you’d use CoCreateInstance to instantiate a COM object, but some APIs like DirectX have a special function to instantiate a factory object used to instantiate further objects.

Once you have your object you’d probably want to use some sort of ComPtr smart pointer to automatically handle AddRef/Release stuff. wio provides this for example:

You probably are interested in the WMI COM api, so you can find more documentation on it at

As it turns out there is already a PR for winapi that adds bindings to the WMI stuff so it won’t be too long before it’ll be merged and you can work off a fork for now if you want.


Thanks for that. I’ll wait for the wmi bindings to arrive in winapi.