Created
January 12, 2021 02:00
-
-
Save deadjakk/9a8425686b20f99daf8f1e1a35c00cbf to your computer and use it in GitHub Desktop.
WinExec example from rust (for reference)
This file contains hidden or 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
#[link(name="kernel32")] | |
extern "system" { | |
fn WinExec(lpstr: *mut u8,cmdshow: u32)->u32; | |
} | |
/// &str to a null termed u8bit vector | |
fn str_to_u8(string: &str) -> Vec<u8>{ | |
let mut ret : Vec<u8> = vec![]; | |
for x in string.as_bytes() { | |
println!("{:?}",x); | |
ret.push(*x); | |
} | |
ret.push(0); | |
ret | |
} | |
// window parameter: see more @ https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow | |
// 0 == Hides the window and activates another window. | |
// 3 == mainaximizes window | |
// 6 == minimize window | |
pub fn winexec(command: &str, window: u32){ | |
let ret = unsafe { | |
WinExec(str_to_u8(command).as_mut_ptr(), window); | |
}; | |
} | |
fn main() { | |
//v----shell command | |
winexec("notepad",0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment