public bool InvokeVerb(string verb) { if (string.IsNullOrEmpty(verb)) { return(false); } try { var currentWindows = Win32API.GetDesktopWindows(); var pici = new Shell32.CMINVOKECOMMANDINFOEX(); pici.lpVerb = new SafeResourceId(verb, CharSet.Ansi); pici.nShow = ShowWindowCommand.SW_SHOWNORMAL; pici.cbSize = (uint)Marshal.SizeOf(pici); cMenu.InvokeCommand(pici); Win32API.BringToForeground(currentWindows); return(true); } catch (Exception ex) when( ex is COMException || ex is UnauthorizedAccessException) { Debug.WriteLine(ex); } return(false); }
public void InvokeItem(int itemID) { if (itemID < 0) { return; } try { var currentWindows = Win32API.GetDesktopWindows(); var pici = new Shell32.CMINVOKECOMMANDINFOEX { lpVerb = Macros.MAKEINTRESOURCE(itemID), nShow = ShowWindowCommand.SW_SHOWNORMAL, }; pici.cbSize = (uint)Marshal.SizeOf(pici); cMenu.InvokeCommand(pici); Win32API.BringToForeground(currentWindows); } catch (Exception ex) when( ex is COMException || ex is UnauthorizedAccessException) { Debug.WriteLine(ex); } }