public static bool Start(ProcessStartInfo startInfo, uint mask) { var info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = startInfo.Verb; info.lpFile = startInfo.FileName; switch (startInfo.WindowStyle) { case ProcessWindowStyle.Hidden: info.nShow = ShowCommands.SW_HIDE; break; case ProcessWindowStyle.Minimized: info.nShow = ShowCommands.SW_MINIMIZE; break; case ProcessWindowStyle.Maximized: info.nShow = ShowCommands.SW_MAXIMIZE; break; default: info.nShow = ShowCommands.SW_SHOW; break; } info.lpParameters = startInfo.Arguments; info.lpDirectory = startInfo.WorkingDirectory; info.fMask = mask; return(ShellExecuteEx(ref info)); }
// hook function public static bool ShellExecuteExW_Hook( ref SHELLEXECUTEINFO lpExecInfo) { try { string file = "-1"; string parameters = "-1"; if ((lpExecInfo.lpFile != null) || (lpExecInfo.lpFile.Length > 0)) { file = lpExecInfo.lpFile; } if ((lpExecInfo.lpParameters != null) || (lpExecInfo.lpParameters.Length > 0)) { parameters = lpExecInfo.lpParameters; } reportEvent(ShellExecuteExWStr, file, parameters); } catch { // swallow exceptions so that any issues caused by this code do not crash target process } return(ShellExecuteExW(ref lpExecInfo)); }
/// <summary> /// RunWithElevatedProcess /// </summary> /// <exception cref="Exception">Run error.</exception> /// <param name="executable"></param> /// <param name="args"></param> public static void RunWithElevatedProcess(string executable, string[] args) { string arg = string.Empty; arg = args == null ? String.Empty : args.Aggregate(arg, (current, s) => current + String.Format(" \"{0}\"", s)); var shExecInfo = new SHELLEXECUTEINFO(); shExecInfo.cbSize = Marshal.SizeOf(shExecInfo); shExecInfo.fMask = 0; shExecInfo.hwnd = IntPtr.Zero; shExecInfo.lpVerb = "runas"; shExecInfo.lpFile = executable; shExecInfo.lpParameters = arg; shExecInfo.lpDirectory = Path.GetDirectoryName(executable); ; if (ShellExecuteEx(ref shExecInfo) == false) { throw new Exception(string.Format( "Error when run with elevated LE.\r\n" + "Executable: {0}\r\n" + "Arguments: {1}", executable, arg)); } }
/// <summary> /// RunWithElevatedProcess /// </summary> /// <exception cref="Exception">Run error.</exception> /// <param name="executable"></param> /// <param name="args"></param> public static void RunWithElevatedProcess(string executable, string[] args) { var arg = string.Empty; arg = args == null ? string.Empty : args.Aggregate(arg, (current, s) => current + $" \"{s}\""); var shExecInfo = new SHELLEXECUTEINFO(); shExecInfo.cbSize = Marshal.SizeOf(shExecInfo); shExecInfo.fMask = 0; shExecInfo.hwnd = IntPtr.Zero; shExecInfo.lpVerb = "runas"; shExecInfo.lpFile = executable; shExecInfo.lpParameters = arg; shExecInfo.lpDirectory = Path.GetDirectoryName(executable); ; if (ShellExecuteEx(ref shExecInfo) == false) { throw new Exception("Error when run with elevated LE.\r\n" + $"Executable: {executable}\r\n" + $"Arguments: {arg}"); } }
public static void ProcessStart(string executable, string[] args, int show = 1) { var arg = string.Empty; arg = args == null ? string.Empty : args.Aggregate(arg, (current, s) => current + $" {s}"); var shExecInfo = new SHELLEXECUTEINFO(); shExecInfo.cbSize = Marshal.SizeOf(shExecInfo); shExecInfo.fMask = 0; shExecInfo.hwnd = IntPtr.Zero; shExecInfo.lpVerb = "runas"; shExecInfo.lpFile = executable; shExecInfo.lpParameters = arg; shExecInfo.nShow = show; if (ShellExecuteEx(ref shExecInfo) == false) { throw new Exception("Error.\r\n" + $"Executable: {executable}\r\n" + $"Arguments: {arg}"); } }
public void ExpandFile(string fileName, string path) { try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "open"; info.lpFile = "expand.exe"; info.lpDirectory = path; if (path.Substring(path.Length - 1, 1) == "\\") { path = path.Substring(0, path.Length - 1); } info.lpParameters = "-F:* \"" + fileName + "\" \"" + path + "\""; info.fMask = 67142464; ShellExecuteEx(ref info); if (info.hProcess != new IntPtr(0)) { WaitForSingleObject(info.hProcess, 0xFFFFFFFF); CloseHandle(info.hProcess); } } catch (Exception E) { MessageBoxShow(E.Source + "\r\n" + E.StackTrace + "\r\n" + E.Message); } }
static bool ShellExecuteEx_Hooked(ref SHELLEXECUTEINFO lpExecInfo) { try { var uri = new Uri(lpExecInfo.lpFile); //"https?://osu\.ppy\.sh/[bsd]/" //"https?://bloodcat.com/osu/m/" if (uri.Host == "osu.ppy.sh" && "b/d/s/".Contains(uri.Segments[1]) || uri.Host == "bloodcat.com" && uri.AbsolutePath.StartsWith("/osu/m/")) { string request = lpExecInfo.lpFile; var worker = new Thread(() => InvokeUrlHooker.BloodcatDownload(request)); worker.SetApartmentState(ApartmentState.STA); worker.Start(); return(true); } } catch (Exception e) { } //call original API... return(ShellExecuteEx(ref lpExecInfo)); }
private static void ShellExecuteExNet(ref SHELLEXECUTEINFO lpExecInfo) { if (!ShellExecuteEx(ref lpExecInfo)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public static void OpenPath(string url) { var info = new SHELLEXECUTEINFO(IntPtr.Zero); info.lpVerb = "open"; info.lpFile = url; info.fMask = SHELLEXECUTEINFO.FMASK.SEE_MASK_FLAG_NO_UI; var ret = ShellExecuteExW(ref info); }
public static void OpenPropertiesDialog(IntPtr hWnd, string file) { var info = new SHELLEXECUTEINFO(hWnd); info.lpVerb = "properties"; info.lpFile = file; info.fMask = SHELLEXECUTEINFO.FMASK.SEE_MASK_CONNECTNETDRV | SHELLEXECUTEINFO.FMASK.SEE_MASK_UNICODE | SHELLEXECUTEINFO.FMASK.SEE_MASK_NOCLOSEPROCESS | SHELLEXECUTEINFO.FMASK.SEE_MASK_INVOKEIDLIST | SHELLEXECUTEINFO.FMASK.SEE_MASK_FLAG_NO_UI; var ret = ShellExecuteExW(ref info); }
public static void ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo) { bool ok = _ShellExecuteEx(ref lpExecInfo); if (!ok) { throw new Win32Exception(); } }
public bool OnShellExecution(ref SHELLEXECUTEINFO info) { if (handler == null) { return(true); } return(handler.OnShellExecution(ref info)); }
public static bool ShowFileProperties(string Filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = Filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; return ShellExecuteEx(ref info); }
public static void ShowFileProperties(string filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.Size = System.Runtime.InteropServices.Marshal.SizeOf(info); info.Verb = "properties"; info.File = filename; info.Show = SW_SHOW; info.Mask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); }
public static void Runas(string Filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "runas"; info.lpFile = Filename; info.nShow = 5; info.fMask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); }
public bool ShellExecuteExHook(ref SHELLEXECUTEINFO lpExecInfo) { //server.ReportMessage("ShellExecuteExW: " + lpExecInfo.lpFile); if (!server.OnShellExecution(ref lpExecInfo)) { return(ShellExecuteEx(ref lpExecInfo)); } return(true); }
public static void ShowFileProperties(string path) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = path; info.nShow = 5; info.fMask = 12; ShellExecuteEx(ref info); }
public static bool Show(string filename) { var info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; return(ShellExecuteEx(ref info)); }
public void ShowFileProperties(object sender, RoutedEventArgs e) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = (SearchResultsListView.SelectedItem as SearchResult).FullPathAndFileName; info.nShow = 5; info.fMask = 12; ShellExecuteEx(ref info); }
public static bool ShowFileProperties(string Filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = Filename; info.nShow = (int)WindowShowStyle.Show; info.fMask = SEE_MASK_INVOKEIDLIST; return(ShellExecuteEx(ref info)); }
public static void ShowFileProperties(string Filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = Filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); }
public static int PropertyFileOrDirectory(string path) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = path.ToString(); info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; return(ShellExecuteEx(ref info)); }
/// <summary>Opens the shell properties dialog for a given file or folder path (GW is needed for that, not available from TW or Console).</summary> /// <param name="filePath">The full file- or folder path.</param> public static void ShowFileProperties(Primitive filePath) { string fileName = Environment.ExpandEnvironmentVariables(filePath); SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = fileName; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); }
internal static bool ShowFileProperties(string Filename) { var info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpParameters = "details"; info.lpFile = Filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; return(ShellExecuteEx(ref info)); }
public static Process ShellExec([NotNull] string fileName, string arguments, ShellSettings settings) { settings ??= ShellSettings.Default; SHELLEXECUTEINFO info = GetShellExecuteInfo(fileName, arguments, settings); Process p = InternalShellExec(info); if (p != null && !settings.JobHandle.IsInvalidHandle()) { ProcessJob.AddProcess(settings.JobHandle, p); } return(p); }
public static bool ShowFileSecurityProperties(string filename, IntPtr parentHandle) { var info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; info.hwnd = parentHandle; info.lpParameters = "Digital signatures"; return(ShellExecuteEx(ref info)); }
public static Process ShellExec(IntPtr lpIDList, ShellSettings settings) { if (lpIDList.IsZero()) { throw new ArgumentNullException(nameof(lpIDList)); } settings ??= ShellSettings.Default; SHELLEXECUTEINFO info = GetShellExecuteInfo(settings); info.lpIDList = lpIDList; info.fMask |= (int)ShellExecuteMaskFlagsEnum.SEE_MASK_IDLIST; return(InternalShellExec(info)); }
private static bool ShowFileSecurityProperties(string Filename, IntPtr parentHandle) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = Filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; info.hwnd = parentHandle; info.lpParameters = "Security"; // Opens the file properties on the Security tab return(ShellExecuteEx(ref info)); }
/// <summary> /// 指定したファイルまたはフォルダーのプロパティダイアログを表示します。 /// </summary> /// <param name="path">ファイルまたはフォルダーのパス。</param> public static void ShowProperty(string path) { Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(path)); var shei = SHELLEXECUTEINFO.Create(HWND_DESKTOP); shei.fMask = SEE_MASK.SEE_MASK_NOCLOSEPROCESS | SEE_MASK.SEE_MASK_INVOKEIDLIST | SEE_MASK.SEE_MASK_FLAG_NO_UI; shei.lpFile = path; shei.lpVerb = "properties"; shei.nShow = SW_HIDE; WindowsShellNativeMethods.ShellExecuteEx(ref shei); }
public static bool ShowPropertiesDialog(string filePath) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO { lpVerb = "Properties", //lpParameters = "详细信息";//显示选项卡,此处有语言差异 lpFile = filePath, nShow = SW_SHOW, fMask = SEE_MASK_INVOKEIDLIST, cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)) }; return(ShellExecuteEx(ref info)); }
public static void OpenPropertiesDialog(string fullPath) { var info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = "\"" + fullPath + "\""; info.nShow = (int)NativeConsts.ShellShowCommands.SW_SHOW; info.fMask = (uint)NativeConsts.ShellExecuteMaskFlags.SEE_MASK_INVOKEIDLIST; if (!NativeMethods.ShellExecuteEx(ref info)) { throw new Win32Exception(); } }
public static bool OpenWithDialog(ILogicItem itemToOpenWith) { if (itemToOpenWith == null) throw new ArgumentNullException("itemToOpenWith", "Не выбрана сущность для получения атрибутов"); if (itemToOpenWith.Length == long.MinValue) throw new ArgumentException("itemToOpenWith", "Выбрана папка"); var shInfo = new SHELLEXECUTEINFO { cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)), lpFile = "rundll32.exe", lpParameters = "shell32.dll,OpenAs_RunDLL " + itemToOpenWith.Info.FullName, nShow = SwShow, fMask = SeeMaskInvokeidlist, lpVerb = "open" }; return ShellExecuteEx(shInfo) == 1; }
private static extern int ShellExecute(ref SHELLEXECUTEINFO s);
public static extern Int32 ShellExecuteEx( ref SHELLEXECUTEINFO lpExecInfo);
/// <summary> /// プロパティダイアログを表示する /// </summary> /// <param name="owner">ダイアログボックスを所有する IWin32Window の実装</param> /// <param name="fileName">プロパティを表示するファイル名</param> public static void ShowPropertyDialog(IWin32Window owner, string fileName) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = (uint)Marshal.SizeOf(info); info.fMask = ShellExecuteMaskFlag.SEE_MASK_INVOKEIDLIST | ShellExecuteMaskFlag.SEE_MASK_FLAG_NO_UI; info.hwnd = (owner == null ? IntPtr.Zero : owner.Handle); info.lpFile = fileName; info.lpVerb = "properties"; info.lpParameters = null; info.lpDirectory = null; info.nShow = 0; info.lpIDList = IntPtr.Zero; if (!ShellExecuteEx(ref info)) { // エラーコードに応じた例外をスローする switch ((ShellExecuteErrors)Marshal.GetLastWin32Error()) { case ShellExecuteErrors.SE_ERR_FNF: throw new FileNotFoundException(); case ShellExecuteErrors.SE_ERR_PNF: throw new DirectoryNotFoundException(); case ShellExecuteErrors.SE_ERR_ACCESSDENIED: throw new UnauthorizedAccessException(); case ShellExecuteErrors.SE_ERR_OOM: throw new OutOfMemoryException(); case ShellExecuteErrors.SE_ERR_DLLNOTFOUND: throw new DllNotFoundException(); default: throw new Win32Exception(); } } }
public bool FilePropertiesDialog(ILogicItem itemToAttribute) { if (itemToAttribute == null) throw new ArgumentNullException("itemToAttribute", "Не выбрана сущность для получения атрибутов"); var shInfo = new SHELLEXECUTEINFO { cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)), lpFile = itemToAttribute.Info.FullName, nShow = SwShow, fMask = SeeMaskInvokeidlist, lpVerb = "properties" }; return ShellExecuteEx(shInfo) == 1; }
private static extern int ShellExecuteEx(SHELLEXECUTEINFO shinfo);
private static void RunWithElevatedProcess(string[] args) { string arg = String.Empty; arg = args.Aggregate(arg, (current, s) => current + String.Format(" \"{0}\"", s)); var shExecInfo = new SHELLEXECUTEINFO(); shExecInfo.cbSize = Marshal.SizeOf(shExecInfo); shExecInfo.fMask = 0; shExecInfo.hwnd = IntPtr.Zero; shExecInfo.lpVerb = "runas"; shExecInfo.lpFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEProc.exe"); shExecInfo.lpParameters = arg; shExecInfo.lpDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ; if (ShellExecuteEx(ref shExecInfo) == false) { MessageBox.Show("Error when run with elevated LE."); } }
/// <summary> /// Hiển thị hộp thoại Properties của tập tin, thư mục /// </summary> /// <param name="fileName">Đường dẫn của tập tin</param> /// <param name="hwnd"></param> public static void DisplayFileProperties(string fileName, IntPtr hwnd) { const int SEE_MASK_INVOKEIDLIST = 0xc; const int SW_SHOW = 5; SHELLEXECUTEINFO shInfo = new SHELLEXECUTEINFO(); shInfo.cbSize = Marshal.SizeOf(shInfo); shInfo.lpFile = fileName; shInfo.nShow = SW_SHOW; shInfo.fMask = SEE_MASK_INVOKEIDLIST; shInfo.lpVerb = "properties"; shInfo.hwnd = hwnd; ShellExecute(ref shInfo); }
public static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO si);
private void toolInfo_Click(object sender, EventArgs e) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = Marshal.SizeOf(info); info.lpVerb = "properties"; if (curList == ListType.Computer) { info.lpFile = (listFiles.SelectedItems[0].Text); } else if (curList == ListType.Dir) { info.lpFile = (curDir.FullName + Path.DirectorySeparatorChar + listFiles.SelectedItems[0].Text); } info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); }
public static extern Int32 ShellExecuteEx( ref SHELLEXECUTEINFO lpExecInfo); // Address of a SHELLEXECUTEINFO structure that contains and receives
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
private static void ExecuteShellVerb(string filePath, ShellVerbs verb) { if (string.IsNullOrWhiteSpace(filePath)) return; SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = verb.ToString().ToLower(); //"properties"; info.lpFile = filePath; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); }