Verbatim large column https://www.dazhuanlan.com/2019/08/26/5d634448991f8/
WindowStyle
GUI for setting the process window. Control panel process invalid.
In addition, GUI process can take the initiative to ignore this parameter.
UseShellExecute
Refers to the implementation of the system implementation is (true) or process creation process (false).
When true equivalent user double-clicks a document, this time FileName
not limited to, the executable file (.exe), such as URL, bat document can be;
for the process used false CreateProcess
to create a process, more control over the process, but FileName
must be executable documentation (.exe).
Trade-offs:
When you can run the command as an administrator, or executed is not an executable file, this value must be true.
When the need to redirect the input and output (RedirectStandard * = true), this value must be false.
CreateNoWindow
Effective control panel window, UseShellExecute used in combination.
When UseShellExecute = true value is invalid, the normal startup mode.
UseShellExecute = false; when CreateNoWindow = true, the control panel window is not displayed. In this way the process can not be closed by the window, so the process runs the best finish you can run yourself off, or need to go to the Task Manager to close.
Verb
Right-click menu of the document, in addition to "open", depending on the document will be a "print", "Edit", "Run as Administrator" and other options, Verb control is this option.
You can new ProcessStartInfo(FileName).Verbs
view a particular document support of Verb.
Common startup mode
Admin Run
ProcessStartInfo.Verb = "RunAs";
In the Admin process, run as a normal privileges
ProcessStartInfo.FileName = "RunAs";
ProcessStartInfo.Arguments = $"/trustlevel:0x20000 {YOUR_COMMAND}";
YOUR_COMMAND
For the command you want to run, use quotation marks around that contain spaces, and if the command contains quotes, need to be "
in place.
In the run CMD command
ProcessStartInfo.FileName = "cmd";
ProcessStartInfo.Arguments = $"/c {YOUR_COMMAND}";
YOUR_COMMAND
Similarly to the above, but instead of quotation marks to use two commands, "
-> ""
.
Explorer to locate the document
PATH is of a document:
ProcessStartInfo.FileName = "explorer";
ProcessStartInfo.Arguments = $"/select, {PATH}";
When a directory PATH ProcessStartInfo.Arguments = PATH;
can be.
Support library chained calls
I wrote a library:) XJKdotNetLibrary
It calls for a common way of doing the packaging, Demo as follows:
ProcessInfoChain.New(Command, Args)
.SetWindow(WindowType.Maximized)
.LaunchBy(LaunchType.CmdStart)
.RunAs(Privilege.Admin)
.Excute()
.Catch(ex=>{throw ex;})
.Finally(result=>{ });
There is also a simpler package:
Cmd.Explorer("C:\");
Cmd.RunSmart("http://xujinkai.net");
Cmd.RunAsAdmin("cmd", "");
//...
Welcome reference ~