Skip to content

Instantly share code, notes, and snippets.

@leiless
Created August 22, 2023 03:20
Show Gist options
  • Save leiless/72757d80255e708d90677022ebf22d57 to your computer and use it in GitHub Desktop.
Save leiless/72757d80255e708d90677022ebf22d57 to your computer and use it in GitHub Desktop.
Get Start Menu path with windows-rs
fn main() -> Result<(), Box<dyn std::error::Error>> {
let guids = vec![
windows::Win32::UI::Shell::FOLDERID_StartMenu, // Current user
windows::Win32::UI::Shell::FOLDERID_CommonStartMenu, // All user
];
for guid in guids {
let start_menu_path = unsafe {
windows::Win32::UI::Shell::SHGetKnownFolderPath(
&guid as _,
windows::Win32::UI::Shell::KF_FLAG_DEFAULT,
windows::Win32::Foundation::HANDLE::default(),
)?.to_string()?
};
println!("{}", start_menu_path);
}
Ok(())
}
@leiless
Copy link
Author

leiless commented Aug 22, 2023

$ cross build --target x86_64-pc-windows-gnu

$ .\windows-rs-start-menu-path.exe
C:\Users\foobar\AppData\Roaming\Microsoft\Windows\Start Menu
C:\ProgramData\Microsoft\Windows\Start Menu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment