-
Notifications
You must be signed in to change notification settings - Fork 512
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
Handling Option<&mut Option<IWbemClassObject>>
InParams
#2040
Comments
I changed my unsafe {
let mut pObject = std::mem::zeroed::<Option<IWbemClassObject>>();
services.GetObject(
&BSTR::from("Win32_Process"),
0,
InParam::null(),
Some(&mut pObject),
None
)?;
} I am also receiving "the trait bound |
Does this help: #2041 It takes advantage of some improvements to the |
That is a great example for querying. Unfortunately my case is the least documented across fn main() -> Result<(), Box<dyn std::error::Error>> {
initialize()?;
let locator = create_locator()?;
let services = create_services(&locator, r"root\cimv2")?;
set_proxy(&services)?;
unsafe {
let mut pObject = mem::zeroed::<Option<IWbemClassObject>>();
services.GetObject(
&BSTR::from("Win32_Service"),
0,
InParam::null(),
Some(&mut pObject),
None
)?;
if let Some(pObject) = pObject {
let mut pInParams = mem::zeroed::<Option<IWbemClassObject>>();
let mut pOutParams = mem::zeroed::<Option<IWbemClassObject>>();
pObject.GetMethod(
w!("ChangeStartMode"),
0,
&mut pInParams,
&mut pOutParams
)?;
let mut pInParams = if let Some(pInParams) = pInParams {
Some(pInParams.SpawnInstance(0)?)
} else {
None
};
let mut pOutParams = if let Some(pOutParams) = pOutParams {
Some(pOutParams.SpawnInstance(0)?)
} else {
None
};
if let Some(pInParams) = &pInParams {
let mut cmd = VARIANT::default();
let mut mode = BSTR::from("Manual");
(*cmd.Anonymous.Anonymous).vt = VT_BSTR;
*(*cmd.Anonymous.Anonymous).Anonymous.bstrVal = mode;
pInParams.Put(
w!("StartMode"),
0,
&cmd,
0
)?;
VariantClear(&mut cmd)?;
}
services.ExecMethod(
&BSTR::from("Win32_Service.Name=\"aspnet_state\""),
&BSTR::from("ChangeStartMode"),
0,
InParam::null(),
&pInParams.unwrap(),
None,
None
)?;
}
}
Ok(())
} |
OK, I see using the WMI API in this way is overly complicated. Let me get that fixed and update the sample. |
The most egregious example that would need the most attention are the various |
Yes, I tried simplifying your example but the let mut object = None;
server.GetObject(&BSTR::from("Win32_Service"), 0, None, Some(&mut object), None)?;
if let Some(object) = object {
let mut in_params = None;
let mut out_params = None;
object.GetMethod(w!("ChangeStartMode"), 0, &mut in_params, &mut out_params)?;
let in_params = if let Some(in_params) = in_params { Some(in_params.SpawnInstance(0)?) } else { None };
if let Some(in_params) = &in_params {
let mut value = VARIANT::default();
(*value.Anonymous.Anonymous).vt = VT_BSTR;
*(*value.Anonymous.Anonymous).Anonymous.bstrVal = BSTR::from("Manual");
in_params.Put(w!("StartMode"), 0, &value, 0)?;
VariantClear(&mut value)?;
server.ExecMethod(&BSTR::from("Win32_Service.Name=\"Fax\""), &BSTR::from("ChangeStartMode"), 0, None, in_params, None, None)?;
}
} I hope to get to |
Didn't realize the PR closed this issue. Let me know if there's anything I can do to help. |
All is well! I fumbled my way through getting it to work. Now I just have a heap corruption error that I need to find what is causing it! |
I am attempting to use
IWbemServices::GetObject
in order to subsequently callIWbemClassObject::{GetMethod, SpawnInstance, Put}
in an effort to call WMI methods. Below is my current attempt with the issue being it feels extremely clunky trying to handlepObject
or just do anything with it period.GetObject
doesn't seem to be returning the object to me and I'm attempting to do this as closely as I did inwinapi
where my existing code is working, to no avail. What am I doing wrong?Note: This is the signature of
GetObject
:The text was updated successfully, but these errors were encountered: