通过Process调用桌面程序

本文介绍了一种使用C#中的Process类启动并控制桌面应用程序的方法,通过向CMD发送命令来实现对指定程序的参数化启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过Process调用桌面程序

ExpandedBlockStart.gifView Code
 1 private void Form1_Load(object sender, EventArgs e)
 2         {
 3             string userid = "admin";
 4             string password = "00";
 5             string[] cmd = new string[] { @"cd E:\Project\DotNet\bin\Debug""PhotoMan.exe $StartFromEIP$ " + userid + " " + assword };
 6 
 7             Process p = new Process();
 8             p.StartInfo.FileName = "cmd.exe";
 9             p.StartInfo.UseShellExecute = false;
10             p.StartInfo.RedirectStandardInput = true;
11             p.StartInfo.RedirectStandardOutput = true;
12             p.StartInfo.RedirectStandardError = true;
13             p.StartInfo.CreateNoWindow = true;
14             p.Start();
15             p.StandardInput.AutoFlush = true;
16             for (int i = 0; i < cmd.Length; i++)
17             {
18                 p.StandardInput.WriteLine(cmd[i].ToString());
19             }
20             p.StandardInput.WriteLine("exit");
21             string strRst = p.StandardOutput.ReadToEnd();
22             p.WaitForExit();
23             p.Close();
24             Form1_FormClosed(nullnull);
25 
26         }
27 
28         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
29         {
30             Application.Exit();
31         }

 

 

转载于:https://www.cnblogs.com/peijian708/archive/2012/02/02/2335765.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值