And*_*age 213
正如Matt Hamilton所建议的那样,对进程进行有限控制的快速方法是在System.Diagnostics.Process类上使用静态Start方法......
using System.Diagnostics;
...
Process.Start("process.exe");
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用Process类的实例.这允许对进程进行更多控制,包括调度,它将运行的窗口类型,以及对我来说最有用的等待进程完成的能力.
using System.Diagnostics;
...
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "process.exe";
process.StartInfo.Arguments = "-n";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
process.WaitForExit();// Waits here for the process to exit.
Run Code Online (Sandbox Code Playgroud)
这种方法比我提到的控制更多.
GvS*_*GvS 10
正如Matt所说,使用Process.Start.
您可以传递URL或文档.它们将由注册的应用程序启动.
例:
Process.Start("Test.Txt");
Run Code Online (Sandbox Code Playgroud)
这将启动加载了Text.Txt的Notepad.exe.
我在自己的程序中使用了以下内容.
Process.Start("http://www.google.com/etc/etc/test.txt")
Run Code Online (Sandbox Code Playgroud)
这有点基础,但它确实适合我.
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "/YourSubDirectory/yourprogram.exe");
Process.Start(new ProcessStartInfo(path));
Run Code Online (Sandbox Code Playgroud)
class ProcessStart
{
static void Main(string[] args)
{
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs";
notePad.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用此语法运行任何应用程序:
System.Diagnostics.Process.Start("Example.exe");
Run Code Online (Sandbox Code Playgroud)
和URL一样.只需在此之间写下您的URL即可()
.
例:
System.Diagnostics.Process.Start("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)
如果在 Windows 上使用
Process process = new Process();
process.StartInfo.FileName = "Test.txt";
process.Start();
Run Code Online (Sandbox Code Playgroud)
适用于 .Net Framework,但对于 Net core 3.1 还需要将 UseShellExecute 设置为 true
Process process = new Process();
process.StartInfo.FileName = "Test.txt";
process.StartInfo.UseShellExecute = true;
process.Start();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
257191 次 |
最近记录: |