/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmd">the index of the command to invoke</param> /// <param name="parentDir">the parent directory from where to invoke</param> /// <param name="ptInvoke">the point (in screen codinates) from which to invoke</param> public static void InvokeCommand(IContextMenu iContextMenu, uint cmd, string parentDir, System.Windows.Point ptInvoke) { CMINVOKECOMMANDINFOEX invoke = new CMINVOKECOMMANDINFOEX(); invoke.cbSize = Shell32Wrapper.cbInvokeCommand; invoke.lpVerb = (IntPtr)cmd; invoke.lpDirectory = parentDir; invoke.lpVerbW = (IntPtr)cmd; invoke.lpDirectoryW = parentDir; //invoke.fMask = CMIC.UNICODE | CMIC.PTINVOKE | // ((Control.ModifierKeys & Keys.Control) != 0 ? CMIC.CONTROL_DOWN : 0) | // ((Control.ModifierKeys & Keys.Shift) != 0 ? CMIC.SHIFT_DOWN : 0); invoke.fMask = CMIC.UNICODE | CMIC.PTINVOKE; invoke.ptInvoke = new POINT() { x = (int)ptInvoke.X, y = (int)ptInvoke.Y }; invoke.nShow = SW.SHOWNORMAL; iContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes the Rename command on the shell item. /// </summary> public void InvokeRename() { CMINVOKECOMMANDINFO invoke = new CMINVOKECOMMANDINFO(); invoke.cbSize = Marshal.SizeOf(invoke); invoke.lpVerb = "rename"; _contextMenu.InvokeCommand(ref invoke); }
public int Popup(IntPtr handle, int x, int y) { Create(); uint cmd = RUser32.TrackPopupMenuEx(_menuHandle, ETrackPopupMenu.RETURNCMD, x, y, handle, IntPtr.Zero); _menuHandle = IntPtr.Zero; if (cmd >= RWinShell.CMD_FIRST) { SCmInvokeCommandInfoEX invoke = new SCmInvokeCommandInfoEX(); invoke.cbSize = Marshal.SizeOf(typeof(SCmInvokeCommandInfoEX)); invoke.lpVerb = (IntPtr)(cmd - 1); invoke.lpDirectory = string.Empty; invoke.fMask = 0; invoke.ptInvoke = new SPoint(); invoke.ptInvoke.x = x; invoke.ptInvoke.y = y; invoke.nShow = 1; _face.InvokeCommand(ref invoke); } return((int)cmd); }
private static void InvokeCommand(IContextMenu oContextMenu, uint nCmd, string strFolder, Point pointInvoke) { var invoke = new Structs.Cminvokecommandinfoex { cbSize = CbInvokeCommand, lpVerb = (IntPtr)(nCmd - CmdFirst), lpDirectory = strFolder, lpVerbW = (IntPtr)(nCmd - CmdFirst), lpDirectoryW = strFolder, fMask = Enums.Cmic.UNICODE | Enums.Cmic.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? Enums.Cmic.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? Enums.Cmic.SHIFT_DOWN : 0), ptInvoke = new Structs.Point(pointInvoke.X, pointInvoke.Y), nShow = Enums.Sw.SHOWNORMAL }; oContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmd">the index of the command to invoke</param> /// <param name="parentDir">the parent directory from where to invoke</param> /// <param name="ptInvoke">the point (in screen co顤dinates) from which to invoke</param> public static void InvokeCommand(IContextMenu iContextMenu, uint cmd, string parentDir, Point ptInvoke) { ShellAPI.CMINVOKECOMMANDINFOEX invoke = new ShellAPI.CMINVOKECOMMANDINFOEX(); invoke.cbSize = ShellAPI.cbInvokeCommand; invoke.lpVerb = (IntPtr)cmd; invoke.lpDirectory = parentDir; invoke.lpVerbW = (IntPtr)cmd; invoke.lpDirectoryW = parentDir; invoke.fMask = ShellAPI.CMIC.UNICODE | ShellAPI.CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? ShellAPI.CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? ShellAPI.CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new ShellAPI.POINT(ptInvoke.X, ptInvoke.Y); invoke.nShow = ShellAPI.SW.SHOWNORMAL; iContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmd">the index of the command to invoke</param> /// <param name="parentDir">the parent directory from where to invoke</param> /// <param name="ptInvoke">the point (in screen coördinates) from which to invoke</param> public static void InvokeCommand(IContextMenu iContextMenu, string cmd, string parentDir, Point ptInvoke) { ShellFolders.CMINVOKECOMMANDINFOEX invoke = new ShellFolders.CMINVOKECOMMANDINFOEX(); invoke.cbSize = ShellFolders.cbInvokeCommand; invoke.lpVerb = Marshal.StringToHGlobalAnsi(cmd); invoke.lpDirectory = parentDir; invoke.lpVerbW = Marshal.StringToHGlobalAnsi(cmd); invoke.lpDirectoryW = parentDir; invoke.fMask = ShellFolders.CMIC.UNICODE | ShellFolders.CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? ShellFolders.CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? ShellFolders.CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new ShellFolders.POINT(ptInvoke.X, ptInvoke.Y); invoke.nShow = NativeMethods.WindowShowStyle.ShowNormal; iContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="workingDir">the parent directory from where to invoke</param> /// <param name="cmd">the index of the command to invoke</param> /// <param name="ptInvoke">the point (in screen coordinates) from which to invoke</param> protected void InvokeCommand(IContextMenu iContextMenu, string workingDir, uint cmd, Point ptInvoke) { CMINVOKECOMMANDINFOEX invoke = new CMINVOKECOMMANDINFOEX(); invoke.cbSize = Interop.cbInvokeCommand; invoke.lpVerb = (IntPtr)cmd; invoke.lpVerbW = (IntPtr)cmd; invoke.lpDirectory = workingDir; invoke.lpDirectoryW = workingDir; invoke.fMask = CMIC.ASYNCOK | CMIC.FLAG_LOG_USAGE | CMIC.UNICODE | CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new NativeMethods.POINT(ptInvoke.X, ptInvoke.Y); invoke.nShow = NativeMethods.WindowShowStyle.ShowNormal; iContextMenu.InvokeCommand(ref invoke); }
private void InvokeCommand(IContextMenu oContextMenu, uint nCmd, string strFolder, bool ctrl, bool shift, int x, int y) { CMINVOKECOMMANDINFOEX invoke = new CMINVOKECOMMANDINFOEX(); invoke.cbSize = s_InvokeCommand; invoke.lpVerb = (IntPtr)(nCmd - CMD_FIRST); invoke.lpDirectory = strFolder; invoke.lpVerbW = (IntPtr)(nCmd - CMD_FIRST); invoke.lpDirectoryW = strFolder; invoke.fMask = CMIC.UNICODE | CMIC.PTINVOKE | (ctrl ? CMIC.CONTROL_DOWN : 0) | (shift ? CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new POINT(x, y); invoke.nShow = SW.SHOWNORMAL; oContextMenu.InvokeCommand(ref invoke); }
private void InvokeCommand(IContextMenu oContextMenu, uint nCmd, string strFolder, Point pointInvoke) { var invoke = new CMINVOKECOMMANDINFOEX(); invoke.cbSize = cbInvokeCommand; invoke.lpVerb = (IntPtr)(nCmd - CMD_FIRST); invoke.lpDirectory = strFolder; invoke.lpVerbW = (IntPtr)(nCmd - CMD_FIRST); invoke.lpDirectoryW = strFolder; invoke.fMask = CMIC.UNICODE | CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new POINT(pointInvoke.X, pointInvoke.Y); invoke.nShow = SW.SHOWNORMAL; oContextMenu.InvokeCommand(ref invoke); }
private static void InvokeCommand(IContextMenu contextMenu, uint nCmd, string strFolder, Point pointInvoke) { CMINVOKECOMMANDINFOEX invoke = new CMINVOKECOMMANDINFOEX { cbSize = cbInvokeCommand, lpVerb = (IntPtr)(nCmd - CMD_FIRST), lpDirectory = strFolder, lpVerbW = (IntPtr)(nCmd - CMD_FIRST), lpDirectoryW = strFolder, fMask = CMIC.UNICODE | CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? CMIC.SHIFT_DOWN : 0), ptInvoke = new POINT(pointInvoke.X, pointInvoke.Y), nShow = SW.SHOWNORMAL }; _ = contextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes the specified verb on the shell item(s). /// </summary> public static void InvokeVerb(this IContextMenu comInterface, string verb) { CMINVOKECOMMANDINFO invoke = new CMINVOKECOMMANDINFO(); invoke.cbSize = (uint)Marshal.SizeOf(invoke); invoke.verb = Marshal.StringToBSTR(verb); // invoke.verb = verb; // comInterface.InvokeCommand(ref invoke); IntPtr refInvoke = Marshal.AllocHGlobal(Marshal.SizeOf(invoke)); Marshal.StructureToPtr(invoke, refInvoke, true); comInterface.InvokeCommand(refInvoke); //// Marshal.PtrToStructure(unmanagedAddr, managedObj); Marshal.FreeHGlobal(refInvoke); refInvoke = IntPtr.Zero; }
private static void InvokeCommand(IContextMenu oContextMenu, uint nCmd, string strFolder, System.Drawing.Point pointInvoke) { var invoke = new CmInvokeCommandInfoEx { cbSize = CbInvokeCommand, lpVerb = (IntPtr)(nCmd - CMD_FIRST), lpDirectory = strFolder, lpVerbW = (IntPtr)(nCmd - CMD_FIRST), lpDirectoryW = strFolder, fMask = Cmic.Unicode | Cmic.Ptinvoke | ((Control.ModifierKeys & Keys.Control) != 0 ? Cmic.ControlDown : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? Cmic.ShiftDown : 0), ptInvoke = new Point(pointInvoke.X, pointInvoke.Y), nShow = Sw.ShowNormal }; oContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmd">the index of the command to invoke</param> /// <param name="parentDir">the parent directory from where to invoke</param> /// <param name="ptInvoke">the point (in screen coördinates) from which to invoke</param> public void InvokeCommand(IContextMenu iContextMenu, IntPtr cmd, string parentDir, System.Drawing.Point ptInvoke) { CMInvokeCommandInfoEx invoke = new CMInvokeCommandInfoEx(); invoke.cbSize = Shell32.cbInvokeCommand; invoke.lpVerb = cmd; invoke.lpDirectory = parentDir; invoke.lpVerbW = cmd; invoke.lpDirectoryW = parentDir; invoke.fMask = (int)(CMIC.UNICODE | CMIC.PTINVOKE); if ((Control.ModifierKeys & Keys.Control) != 0) { invoke.fMask = invoke.fMask | (int)CMIC.CONTROL_DOWN; } if ((Control.ModifierKeys & Keys.Shift) != 0) { invoke.fMask = invoke.fMask | (int)CMIC.SHIFT_DOWN; } invoke.ptInvoke = new System.Drawing.Point(ptInvoke.X, ptInvoke.Y); invoke.nShow = (int)SW.SHOWNORMAL; iContextMenu.InvokeCommand(ref invoke); }
private void InvokeCommand(IContextMenu oContextMenu, uint nCmd, string strFolder, Point pointInvoke) { CMINVOKECOMMANDINFOEX invoke = new CMINVOKECOMMANDINFOEX(); invoke.cbSize = cbInvokeCommand; invoke.lpVerb = (IntPtr)(nCmd - CMD_FIRST); invoke.lpDirectory = strFolder; invoke.lpVerbW = (IntPtr)(nCmd - CMD_FIRST); invoke.lpDirectoryW = strFolder; invoke.fMask = CMIC.UNICODE | CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new POINT(pointInvoke.X, pointInvoke.Y); invoke.nShow = SW.SHOWNORMAL; oContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmdA">the Ansi execute string to invoke</param> /// <param name="cmdW">the Unicode execute string to invoke</param> /// <param name="parentDir">the parent directory from where to invoke</param> /// <param name="ptInvoke">the point (in screen coördinates) from which to invoke</param> public static void InvokeCommand(IContextMenu iContextMenu, string cmd, string parentDir, Point ptInvoke) { ShellAPI.CMINVOKECOMMANDINFOEX invoke = new ShellAPI.CMINVOKECOMMANDINFOEX(); invoke.cbSize = ShellAPI.cbInvokeCommand; invoke.lpVerb = Marshal.StringToHGlobalAnsi(cmd); invoke.lpDirectory = parentDir; invoke.lpVerbW = Marshal.StringToHGlobalUni(cmd); invoke.lpDirectoryW = parentDir; invoke.fMask = ShellAPI.CMIC.UNICODE | ShellAPI.CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? ShellAPI.CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? ShellAPI.CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new ShellAPI.POINT(ptInvoke.X, ptInvoke.Y); invoke.nShow = ShellAPI.SW.SHOWNORMAL; iContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmd">the execute string to invoke</param> /// <param name="parentDir">the parent node from where to invoke</param> /// <param name="ptInvoke">the point (in screen coцrdinates) from which to invoke</param> public static void InvokeCommand(IContextMenu iContextMenu, string cmd, string parentDir, Point ptInvoke) { CMINVOKECOMMANDINFOEX invoke = new CMINVOKECOMMANDINFOEX(); invoke.Size = Marshal.SizeOf(typeof(CMINVOKECOMMANDINFOEX)); invoke.Verb = Marshal.StringToHGlobalAnsi(cmd); invoke.Directory = parentDir; invoke.VerbW = Marshal.StringToHGlobalUni(cmd); invoke.DirectoryW = parentDir; invoke.Mask = CMIC.Unicode | CMIC.PtInvoke | ((Control.ModifierKeys & Keys.Control) != 0 ? CMIC.ControlDown : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? CMIC.ShiftDown : 0); invoke.InvokePoint = new POINT(ptInvoke); invoke.ShowType = SW.ShowNormal; iContextMenu.InvokeCommand(ref invoke); }
/// <summary> /// Invokes a specific command from an IContextMenu /// </summary> /// <param name="iContextMenu">the IContextMenu containing the item</param> /// <param name="cmd">the index of the command to invoke</param> /// <param name="parentDir">the parent directory from where to invoke</param> /// <param name="ptInvoke">the point (in screen coördinates) from which to invoke</param> public static void InvokeCommand(IContextMenu iContextMenu, uint cmd, string parentDir, Point ptInvoke) { NativeShellAPI.CMINVOKECOMMANDINFOEX invoke = new NativeShellAPI.CMINVOKECOMMANDINFOEX(); invoke.cbSize = NativeShellAPI.cbInvokeCommand; invoke.lpVerb = (IntPtr)cmd; invoke.lpDirectory = parentDir; invoke.lpVerbW = (IntPtr)cmd; invoke.lpDirectoryW = parentDir; invoke.fMask = NativeShellAPI.CMIC.UNICODE | NativeShellAPI.CMIC.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? NativeShellAPI.CMIC.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? NativeShellAPI.CMIC.SHIFT_DOWN : 0); invoke.ptInvoke = new NativeShellAPI.POINT(ptInvoke.X, ptInvoke.Y); invoke.nShow = NativeShellAPI.SW.SHOWNORMAL; iContextMenu.InvokeCommand(ref invoke); }
private static void HandleApplicationLaunch(string application, AppServiceRequestReceivedEventArgs args) { var arguments = args.Request.Message.Get("Arguments", ""); var workingDirectory = args.Request.Message.Get("WorkingDirectory", ""); try { Process process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = application; // Show window if workingDirectory (opening terminal) process.StartInfo.CreateNoWindow = string.IsNullOrEmpty(workingDirectory); if (arguments == "runas") { process.StartInfo.UseShellExecute = true; process.StartInfo.Verb = "runas"; if (Path.GetExtension(application).ToLower() == ".msi") { process.StartInfo.FileName = "msiexec.exe"; process.StartInfo.Arguments = $"/a \"{application}\""; } } else if (arguments == "runasuser") { process.StartInfo.UseShellExecute = true; process.StartInfo.Verb = "runasuser"; if (Path.GetExtension(application).ToLower() == ".msi") { process.StartInfo.FileName = "msiexec.exe"; process.StartInfo.Arguments = $"/i \"{application}\""; } } else { process.StartInfo.Arguments = arguments; } process.StartInfo.WorkingDirectory = workingDirectory; process.Start(); } catch (Win32Exception) { Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.Verb = "runas"; process.StartInfo.FileName = application; process.StartInfo.CreateNoWindow = true; process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = workingDirectory; try { process.Start(); } catch (Win32Exception) { try { var split = application.Split(';').Where(x => !string.IsNullOrWhiteSpace(x)); if (split.Count() == 1) { Process.Start(application); } else { var groups = split.GroupBy(x => new { Dir = Path.GetDirectoryName(x), Prog = Win32API.GetFileAssociation(x).Result ?? Path.GetExtension(x) }); foreach (var group in groups) { if (!group.Any()) { continue; } var files = group.Select(x => new ShellItem(x)); using var sf = files.First().Parent; IContextMenu menu = null; try { menu = sf.GetChildrenUIObjects <IContextMenu>(null, files.ToArray()); menu.QueryContextMenu(Vanara.PInvoke.HMENU.NULL, 0, 0, 0, CMF.CMF_DEFAULTONLY); var pici = new CMINVOKECOMMANDINFOEX(); pici.lpVerb = CMDSTR_OPEN; pici.nShow = Vanara.PInvoke.ShowWindowCommand.SW_SHOW; pici.cbSize = (uint)Marshal.SizeOf(pici); menu.InvokeCommand(pici); } finally { foreach (var elem in files) { elem.Dispose(); } if (menu != null) { Marshal.ReleaseComObject(menu); } } } } } catch (Win32Exception) { // Cannot open file (e.g DLL) } catch (ArgumentException) { // Cannot open file (e.g DLL) } } } }
public static bool ExecuteVerb(IWin32Window owner, string verb, string parentName, IContextMenu contextMenu) { if (contextMenu == null) { return false; } CMINVOKECOMMANDINFOEX structure = new CMINVOKECOMMANDINFOEX(); try { structure.cbSize = Marshal.SizeOf(structure); if (verb != null) { structure.lpVerb = Marshal.StringToHGlobalAnsi(verb); structure.lpVerbW = Marshal.StringToHGlobalUni(verb); } if (!string.IsNullOrEmpty(parentName)) { structure.lpDirectory = parentName; structure.lpDirectoryW = parentName; } if (owner != null) { structure.hwnd = owner.Handle; } structure.fMask = (CMIC.UNICODE | (((Control.ModifierKeys & Keys.Control) > Keys.None) ? CMIC.CONTROL_DOWN : ((CMIC) 0))) | (((Control.ModifierKeys & Keys.Shift) > Keys.None) ? CMIC.SHIFT_DOWN : ((CMIC) 0)); structure.nShow = SW.SW_SHOWNORMAL; contextMenu.InvokeCommand(ref structure); Marshal.ReleaseComObject(contextMenu); } finally { Marshal.FreeHGlobal(structure.lpVerb); Marshal.FreeHGlobal(structure.lpVerbW); } return true; }
private static void InvokeCommand(IContextMenu oContextMenu, uint nCmd, string strFolder, Point pointInvoke) { var invoke = new Structs.Cminvokecommandinfoex { cbSize = CbInvokeCommand, lpVerb = (IntPtr) (nCmd - CmdFirst), lpDirectory = strFolder, lpVerbW = (IntPtr) (nCmd - CmdFirst), lpDirectoryW = strFolder, fMask = Enums.Cmic.UNICODE | Enums.Cmic.PTINVOKE | ((Control.ModifierKeys & Keys.Control) != 0 ? Enums.Cmic.CONTROL_DOWN : 0) | ((Control.ModifierKeys & Keys.Shift) != 0 ? Enums.Cmic.SHIFT_DOWN : 0), ptInvoke = new Structs.Point(pointInvoke.X, pointInvoke.Y), nShow = Enums.Sw.SHOWNORMAL }; oContextMenu.InvokeCommand(ref invoke); }