Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Created Jul 14, 2021
Embed
What would you like to do?
Query the service control manager using the Windows crate
fn main() -> Result<()> {
unsafe {
let scm = OpenSCManagerA(None, None, GENERIC_READ);
let service = OpenServiceA(scm, "Fax", GENERIC_READ);
let mut buffer_size = 0;
QueryServiceStatusEx(
service,
SC_STATUS_PROCESS_INFO,
std::ptr::null_mut(),
0,
&mut buffer_size,
);
let mut buffer = Vec::new();
buffer.resize(buffer_size as _, 0);
if !QueryServiceStatusEx(
service,
SC_STATUS_PROCESS_INFO,
buffer.as_mut_ptr(),
buffer_size,
&mut buffer_size,
)
.as_bool()
{
return Err(HRESULT::from_thread().into());
}
let info = buffer.as_ptr() as *const SERVICE_STATUS_PROCESS;
println!("{:#?}", *info);
Ok(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment