Created
July 14, 2021 19:06
-
-
Save kennykerr/2bb44d6c3081b867b9d90fe7b40c969b to your computer and use it in GitHub Desktop.
Query the service control manager using the Windows crate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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