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.
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. https://github.com/retep998/winapi-rs/pull/603
Just wondered if WMI is yet supported in Rust? At the moment I'm having to bundle a tiny Go program with my Rust application since Go has this library Go wmi. This lets me use the WMI query language, e.g., select ProcessorID from Win32_Processor etc.
WMI support has been merged into winapi. I haven't yet published it to crates.io but you can already start using it by depending on winapi via a git dependency.
Thanks for that. Looks like I've been spoiled by the high level wrappers available for Python and Go since I've never had to do anything as complicated as those examples. Anyway, I'll give it a try.
IWbemLocator does exist in the git version of winapi, it's just not published to crates.io yet. I've also recently added the FAILED function so you can correctly test if an HRESULT indicates failure.