通过Process调用桌面程序

通过Process调用桌面程序

View 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         }

 

 

posted on 2012-02-02 14:47 J-Pei 阅读(...) 评论(...) 编辑 收藏

导航

统计