-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for executing WMI methods #104
base: main
Are you sure you want to change the base?
Conversation
- Adds conversion function from wmi-rs' Variant to windows-rs' VARIANT - Adds custom serializer to take a struct and convert it to a HashMap of (field name, field value) pairs
- Can execute either instance or class methods, but instance methods require the __PATH of the WMI object. - Rust struct conversion to and from IWbemClassObjects is handled by VariantStructSerializer
This resolves the unsafe memory hack that was previously being used, and makes the technique much more scalable.
After looking at how |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi TechnoPorg 👋
Thanks for working on this! This is a great addition to the crate and the impl looks very good.
I left some minor comments, the bigger stuff are:
- Process create test seems flaky on my machine
- Consider exposing
exec_method_native_wrapper
- Consider allowing
In = () / Out = ()
(by default?)
Again, thank you for taking the time to implement this, great work!
src/method.rs
Outdated
} | ||
|
||
#[test] | ||
fn it_exec_instance_method() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running locally, this seems to be flaky for some reason:
failures:
---- method::tests::it_exec_class_method stdout ----
thread 'method::tests::it_exec_class_method' panicked at src\method.rs:162:14:
called `Result::unwrap()` on an `Err` value: SerdeError("invalid type: Option value, expected u32")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- method::tests::it_exec_instance_method stdout ----
thread 'method::tests::it_exec_instance_method' panicked at src\method.rs:177:14:
called `Result::unwrap()` on an `Err` value: SerdeError("invalid type: Option value, expected u32")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran it a few more times on my machine and was able to reproduce this. I'm not sure what's causing it, but the process create method is failing with the generic error code 8 ("unknown failure").
This seems to be happening totally unpredictably, so I don't believe it's tied to this implementation, but I haven't had the chance to test whether it occurs with WMI bindings in other languages. We could ignore the test, or rework it to use another WMI method instead.
WMIConnection now supports calling both instance and class methods with an idiomatic Rust API that automatically serializes and deserializes to/from Rust structs.
The WMI method calling code is based on the example from the windows-rs crate: microsoft/windows-rs#2794
Comments and documentation are still WIP,
and there is an awful hack in struct serialization that I'd like to get rid of,which is why this PR is currently a draft.Closes #18
Closes #58