Provide the native computer name to Windows script processes
This commit is contained in:
@@ -250,16 +250,20 @@ fn registry_string(name: &str) -> Result<String> {
|
||||
);
|
||||
Ok(String::from_utf16(&bytes[..size as usize / 2 - 1])?)
|
||||
}
|
||||
pub fn snapshot() -> Result<Value> {
|
||||
let started = Utc::now();
|
||||
let mut hostname = vec![0u16; 256];
|
||||
let mut len = hostname.len() as u32;
|
||||
pub(crate) fn computer_name(format: COMPUTER_NAME_FORMAT) -> Result<String> {
|
||||
let mut name = [0u16; 256];
|
||||
let mut len = name.len() as u32;
|
||||
ensure!(
|
||||
unsafe { GetComputerNameExW(ComputerNameDnsHostname, hostname.as_mut_ptr(), &mut len) }
|
||||
!= 0,
|
||||
unsafe { GetComputerNameExW(format, name.as_mut_ptr(), &mut len) } != 0
|
||||
&& len > 0 && (len as usize) < name.len(),
|
||||
"HOSTNAME_QUERY"
|
||||
);
|
||||
let hostname = String::from_utf16(&hostname[..len as usize])?;
|
||||
Ok(String::from_utf16(&name[..len as usize])?)
|
||||
}
|
||||
|
||||
pub fn snapshot() -> Result<Value> {
|
||||
let started = Utc::now();
|
||||
let hostname = computer_name(ComputerNameDnsHostname)?;
|
||||
let volume = wide(std::env::var("SystemDrive").context("SYSTEM_DRIVE")? + "\\");
|
||||
let mut available = 0;
|
||||
let mut total = 0;
|
||||
|
||||
Reference in New Issue
Block a user