C# Winform窗体里面怎么打开exe程序
C# Winform窗体里面怎么打开exe程序
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "要调用的exe名称";
process.StartInfo.WorkingDirectory = path//要掉用得exe路径例如:"C:\windows";
process.StartInfo.CreateNoWindow = true;
process.Start();
process.WaitForExit();//无限制的等待,看自己情况要不要加 追问还是在窗体外面显示呀?我把窗体设为了MDI窗体。。。
方法1
private void toolStripButton1_Click(object sender, EventArgs e)
System.Diagnostics.Process p = System.Diagnostics.Process.Start("calc");//notepad");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, this.Handle);
ShowWindowAsync(p.MainWindowHandle, 3);
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild,IntPtr hWndNewParent);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd,int nCmdShow);
//或者
[DllImport("user32.dll")]
static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern int SetParent(int hWndChild, int hWndNewParent);//写在方法里,
System.Diagnostics.Process.Start("calc.exe");
System.Diagnostics.Process.Start("winword.exe.exe");
System.Diagnostics.Process.Start("excel.exe");
System.Diagnostics.Process.Start("notepad.exe");
SetParent(FindWindow(null, "计算器"), this.Handle.ToInt32());//FindWindow(null, "计算器")//第一个参数是类名,第二个是标题名只能是这几个可以,其他的程序就不行
System.Diagnostics.Process.Start("calc.exe");
System.Diagnostics.Process.Start("winword.exe.exe");
System.Diagnostics.Process.Start("excel.exe");
System.Diagnostics.Process.Start("notepad.exe");
方法2
判断con的状态是否为open(),con.State==ConnectionState.Open,如果是则提示成功,否则失败;
方法3
Process.Start("calc");
方法4
System.Diagnostics.Process.Start("绝对路径");
方法5
System.Diagnostics.Process.Start("路径");
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?