-
Notifications
You must be signed in to change notification settings - Fork 523
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
Please provide an example for using WMI ExecMethod
, full with passing arguments and extracting results
#2751
Comments
I'd suggest reaching out to https://stackoverflow.com/search?q=windows-rs |
Well, apparently crowds do not seem to have much to say on this point 🤷 |
@kennykerr any idea how we can make progress on this? |
If you are just looking for help using an API, you can also try: https://docs.microsoft.com/en-us/answers/topics/windows-api.html If you have a minimal repro in C++ and are just looking for help porting to Rust, you can share the minimal repro here and I can take another look. |
I do have a minimal repro, but only in Python as shown on StackOverflow and PowerShell as follows:
|
The comment has its merits, and notably helps me to realize the URL to the driver was incorrect. That example indeed shows API calls I had not encountered before, so I made a first attempt. I get stuck from things that possibly just come from my lack of familiarity with Windows APIs - the particular blocking point here is "how can I feed a Variant containing a BSTR to that
|
I recently added a sample illustrating how to use This has not yet been published, but you add a git dependency to kick the tires: |
That does not seem too far from my attempt at using
Do you mean by this, that unreleased crate functionality is necessary to create a BSTR variant? That would be unfortunate, as wmi-rs still forces me to stick with 0.48 |
It should be possible with older versions, just more complicated. |
I'm starting to consider dropping the Given the number of calls involved, it would likely be useful to have a Rust version of that example. |
Thanks for the example, I'll see if I can write a quick sample. |
My quick incomplete one, inspired by
|
I've expanded the WMI sample to cover |
Great, thanks, I've been able to replicate the However, things are not so easy when in comes to my original API calls:
With let mut in_params_class: Option<Wmi::IWbemClassObject> = None;
unsafe { xs_base.GetMethod(w!("AddSession"), 0,
&mut in_params_class, std::ptr::null_mut()) }?;
let in_params_class = in_params_class.unwrap();
// fill input params
let in_params = unsafe { in_params_class.SpawnInstance(0) }?;
let var_session_name = VARIANT::from("MySession");
unsafe { in_params.Put(w!("Id"), 0, &var_session_name, 0) }?;
// method call
let mut out_params = None;
eprintln!("calling ExecMethod");
unsafe { svc.ExecMethod(
&BSTR::from("CitrixXenStoreBase"),
&BSTR::from("AddSession"),
Default::default(),
None,
&in_params,
Some(&mut out_params),
None,
) }?;
eprintln!("called ExecMethod");
let out_params = out_params.unwrap(); |
Sorry, I don't know anything about "xen" - best of luck! |
Well, my problem in itself is not really Xen-specific, it is centered around the use of the Windows APIs (and tooling). Here (Sorry that part may well be wandering off-topic, likely largely due to me being unfamiliar with the Windows habits) Is there somewhere a description of how WMI works, notably here which component does parameter type checking? My guess would be that it is "something in the Windows-provided stack" rather than the driver implementing the method, and surely there would be some way of getting that something to output some additional traces? I activated logging of WMI events as described here -- as much as I can, as:
|
With some more poking around I understand that:
It's indeed that my use case was a bit different from the one in the example. I was finally able to call that method and extract the output parameters. |
Glad you got it working! |
Suggestion
#2041 adds sample WMI code, but it does not help with the more complex
ExecMethod
mechanism, which needs to be used eg. in a Xen VM to access read/write to XenStore (through xeniface driver).Ideally the experience gained on xenstore-win experimentation could be used to implement an ExecMetho abstraction in
wmi-rs
The text was updated successfully, but these errors were encountered: