Skip to repository content49 lines · 1.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:32:58.763Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
windows.rs
1use windows::Win32::System::Com::{
2 CLSCTX_LOCAL_SERVER, COINIT_APARTMENTTHREADED, CoCreateInstance, CoInitializeEx, IDispatch,
3 IServiceProvider,
4};
5use windows::Win32::System::Variant::VARIANT;
6use windows::Win32::UI::Shell::{
7 CSIDL_DESKTOP, IShellBrowser, IShellDispatch2, IShellFolderViewDual, IShellWindows,
8 SID_STopLevelBrowser, SVGIO_BACKGROUND, SWC_DESKTOP, SWFO_NEEDDISPATCH, ShellWindows,
9};
10use windows::core::{BSTR, Interface};
11
12pub fn shell_execute_from_explorer(
13 file: &str,
14 parameters: &str,
15 directory: &str,
16) -> anyhow::Result<()> {
17 unsafe {
18 CoInitializeEx(None, COINIT_APARTMENTTHREADED).unwrap();
19
20 let mut _hwnd = Default::default();
21 let shell_dispatch: IShellDispatch2 =
22 CoCreateInstance::<_, IShellWindows>(&ShellWindows, None, CLSCTX_LOCAL_SERVER)?
23 .FindWindowSW(
24 &VARIANT::from(CSIDL_DESKTOP as i32),
25 &VARIANT::default(),
26 SWC_DESKTOP,
27 &mut _hwnd,
28 SWFO_NEEDDISPATCH,
29 )?
30 .cast::<IServiceProvider>()?
31 .QueryService::<IShellBrowser>(&SID_STopLevelBrowser)?
32 .QueryActiveShellView()?
33 .GetItemObject::<IDispatch>(SVGIO_BACKGROUND)?
34 .cast::<IShellFolderViewDual>()?
35 .Application()?
36 .cast()?;
37
38 shell_dispatch.ShellExecute(
39 &BSTR::from(file),
40 &VARIANT::from(parameters),
41 &VARIANT::from(directory),
42 &VARIANT::from(""),
43 &VARIANT::from(0i32),
44 )?;
45
46 Ok(())
47 }
48}
49