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("路径");

posted on 2024-02-03 16:06  糯米白白  阅读(161)  评论(0编辑  收藏  举报

导航