我有一个EXE文件引用在我的c#项目。如何从代码中调用EXE文件?
using System.Diagnostics;
class Program
{
static void Main()
{
Process.Start("C:\\");
}
}
如果你的应用程序需要cmd参数,可以这样使用:
using System.Diagnostics;
class Program
{
static void Main()
{
LaunchCommandLineApp();
}
/// <summary>
/// Launch the application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
}
例子:
System.Diagnostics.Process.Start("mspaint.exe");
编译代码
复制代码并将其粘贴到控制台应用程序的Main方法中。 将“mspaint.exe”替换为要运行的应用程序的路径。
例子:
Process process = Process.Start(@"Data\myApp.exe")
int id = process.Id
Process tempProc = Process.GetProcessById(id)
this.Visible = false
tempProc.WaitForExit()
this.Visible = true
推荐文章
- c#忽略证书错误?
- 如何在Visual Studio中找到堆栈跟踪?
- LINQ读取XML
- 如何强制LINQ Sum()返回0而源集合是空的
- 将值附加到查询字符串
- Selenium c# WebDriver:等待元素出现
- 我如何添加双引号的字符串,是在一个变量?
- 如何创建数组。包含不区分大小写的字符串数组?
- 检查字符串是否包含字符串列表中的元素
- 最好的方法在asp.net强制https为整个网站?
- 将字符串转换为System.IO.Stream
- 如何从枚举中选择一个随机值?
- 驻留在App_Code中的类不可访问
- 在链式LINQ扩展方法调用中等价于'let'关键字的代码
- dynamic (c# 4)和var之间的区别是什么?