/// <summary> /// Shows the windows file properties dialog. /// </summary> /// <param name="filename">Full path to file to show properties for.</param> /// <returns>True if successful, otherwise false.</returns> public static bool ShowFileProperties(string filename) { var info = new Shell32.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(Shell32.ShellExecuteEx(ref info)); }
public unsafe bool StartMinimizedNoFocus() { if (string.IsNullOrEmpty(this.StartInfo.FileName)) { throw new InvalidOperationException("Missing StartInfo.FileName"); } if (!this.StartInfo.UseShellExecute) { throw new InvalidOperationException( "Cannot start `minimized no focus` process without ShellExecute"); } // Stop the process if it is currently running this.Close(); fixed(char *fileName = this.StartInfo.FileName.Length > 0?this.StartInfo.FileName : null) fixed(char *verb = this.StartInfo.Verb.Length > 0 ? this.StartInfo.Verb : null) fixed(char *args = this.StartInfo.Arguments.Length > 0 ? this.StartInfo.Arguments : null) fixed(char *directory = this.StartInfo.WorkingDirectory.Length > 0 ? this.StartInfo.WorkingDirectory : null) { Shell32.SHELLEXECUTEINFO shellExecuteInfo = new Shell32.SHELLEXECUTEINFO() { cbSize = (uint)sizeof(Shell32.SHELLEXECUTEINFO), lpFile = fileName, lpVerb = verb, lpParameters = args, lpDirectory = directory, fMask = Shell32.SEE_MASK_NOCLOSEPROCESS | Shell32.SEE_MASK_FLAG_DDEWAIT }; if (this.StartInfo.ErrorDialog) { shellExecuteInfo.hwnd = this.StartInfo.ErrorDialogParentHandle; } else { shellExecuteInfo.fMask |= Shell32.SEE_MASK_FLAG_NO_UI; } shellExecuteInfo.nShow = Shell32.SW_SHOWMINNOACTIVE; ShellExecuteHelper executeHelper = new ShellExecuteHelper(&shellExecuteInfo); if (!executeHelper.ShellExecuteOnSTAThread()) { int error = executeHelper.ErrorCode; if (error == 0) { error = (int)(long)error; } throw new Win32Exception(error); } if (shellExecuteInfo.hProcess != IntPtr.Zero) { // SetProcessHandle(new SafeProcessHandle(shellExecuteInfo.hProcess)); // Invoke the above private emthod through reflection SafeProcessHandle safeHandle = new SafeProcessHandle(shellExecuteInfo.hProcess, true); Type typeProcess = typeof(Process); MethodInfo setProcessHandleMethod = typeProcess.GetMethod("SetProcessHandle", BindingFlags.NonPublic | BindingFlags.Instance); setProcessHandleMethod.Invoke(this, new object[] { safeHandle }); return(true); } } return(false); }