I am trying to get a list of the Local Groups (and eventually the users within those groups) on my Windows system. Using NetLocalGroupEnum in a C++ example worked fine, but when I convert this to Rust's WinAPI it crashes with exit code 3221225477. I have successfully used similar WinAPI code with NetUserEnum to grab the list of local user accounts, but the difference between them appears to be the PDWORD_PTR here, which I suspect I am using incorrectly in my call.
use std::ptr;
use winapi::{
shared::{
basetsd::PDWORD_PTR,
lmcons::MAX_PREFERRED_LENGTH,
minwindef::{DWORD, LPDWORD},
},
um::lmaccess::NetLocalGroupEnum,
};
fn main() {
// [LPCWSTR] If this parameter is NULL, the local computer is used.
let server = ptr::null();
// [DWORD] information level of the data. 1 = LOCALGROUP_INFO_1
let level: DWORD = 1;
// [LPBYTE] Pointer to the address of the buffer that receives the information structure
let mut group_buffer: Vec<u8> = Vec::with_capacity((MAX_PREFERRED_LENGTH) as usize);
let group_buffer_ptr = group_buffer.as_mut_ptr() as *mut _ as *mut _;
// [LPDWORD] count of elements actually enumerated.
let entries_read: LPDWORD = 0u32 as *mut _;
// [LPDWORD] approximate total number of entries that could have been enumerated from the current resume position
let total_entries: LPDWORD = 0u32 as *mut _;
// [PDWORD_PTR] resume handle that is used to continue an existing local group search
let resume_handle: PDWORD_PTR = ptr::null_mut();
// fails with exit code: 3221225477
let ret = unsafe {
NetLocalGroupEnum(
server,
level,
group_buffer_ptr,
MAX_PREFERRED_LENGTH,
entries_read,
total_entries,
resume_handle,
)
};
println!("NetLocalGroupEnum ret = {}", ret);
}
Thanks for any help!