Skip to content

Instantly share code, notes, and snippets.

@deadjakk
Created January 12, 2021 02:00
Show Gist options
  • Save deadjakk/9a8425686b20f99daf8f1e1a35c00cbf to your computer and use it in GitHub Desktop.
Save deadjakk/9a8425686b20f99daf8f1e1a35c00cbf to your computer and use it in GitHub Desktop.
WinExec example from rust (for reference)
#[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