Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用c语言执行/打开程序#_C#_.net - Fatal编程技术网

C# 用c语言执行/打开程序#

C# 用c语言执行/打开程序#,c#,.net,C#,.net,关于如何在C#中打开或执行某些窗口程序,是否有解决方案/参考资料?例如,如果我想打开WinZIP或记事本应用程序 代码行上的示例更有用。但任何事情都是受欢迎的 谢谢。您可以使用该方法 它将处理与默认程序关联的文件: Process.Start(@"C:\path\to\file.zip"); 将使用默认应用程序打开该文件 即使使用URL打开浏览器: Process.Start("http://stackoverflow.com"); // open with default browser

关于如何在C#中打开或执行某些窗口程序,是否有解决方案/参考资料?例如,如果我想打开WinZIP或记事本应用程序

代码行上的示例更有用。但任何事情都是受欢迎的

谢谢。

您可以使用该方法

它将处理与默认程序关联的文件:

Process.Start(@"C:\path\to\file.zip"); 
将使用默认应用程序打开该文件

即使使用URL打开浏览器:

Process.Start("http://stackoverflow.com"); // open with default browser

同意,使您能够更好地控制流程,例如:

ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.FileName = "notepad.exe";
startInfo.Arguments = "file.txt";
startInfo.WorkingDirectory = @"C:\path\to";
startInfo.WindowStyle = ProcessWindowStyle.Maximized;

Process process = Process.Start(startInfo);

// Wait 10 seconds for process to finish...
if (process.WaitForExit(10000))
{
     // Process terminated in less than 10 seconds.
}
else
{
     // Timed out
}

为了更好地控制流程的启动方式,您应该查看ProcessStartInfo,它也可以用作process.Start()的参数。看看这里:嘎。有多少变体“我如何在C#中执行另一个程序?”这样的问题存在?
ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.FileName = "notepad.exe";
startInfo.Arguments = "file.txt";
startInfo.WorkingDirectory = @"C:\path\to";
startInfo.WindowStyle = ProcessWindowStyle.Maximized;

Process process = Process.Start(startInfo);

// Wait 10 seconds for process to finish...
if (process.WaitForExit(10000))
{
     // Process terminated in less than 10 seconds.
}
else
{
     // Timed out
}