当process.waitforexit()处于活动状态时,自动安装程序单击“继续”等

时间:2013-02-18 13:38:43

标签: c#

我根据功能事件编写自动安装程序,例如:

  • 简易编码的自动安装程序,(但很努力地处理所有程序)。

现在我遇到了一个问题,那就是当程序在process.waitforexit()时如何执行sendkeys等?

try
        {
            foreach (string checkedItem in checkedListBox1.CheckedItems)
            {
                if (checkedItem.Contains("."))
                {
                    string str = checkedItem;
                    if (str.Contains("."))
                    {
                        /* haal de rest achter de . eraf om een map ervan te maken. */
                        int index = str.IndexOf('.');
                        string folder = str.Substring(0, index);
                        string pad = Application.StartupPath;
                        try
                        {
                            /* Start de programma. */
                            bool started = false;
                            var process = new Process();
                            process.StartInfo.FileName = pad + "/data/" + folder + "/" + checkedItem;
                            started = process.Start();
                            /* Haal de informatie op van de programma's die opgestart worden. */
                            var processID = process.Id;
                            var processNAAM = process.ProcessName;
                            textBox1.Text += "Gevonden - ID: " + processID + "     NAAM: " + processNAAM + Environment.NewLine;
                            textBox1.Text += DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "  -  " + "Installatie Keuze wordt opgestart." + Environment.NewLine;
                            /* Wacht totdat het programma klaar is! */
                                process.WaitForExit();
                            textBox1.Text += DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "  -  " + "Installatie Geslaagd!" + Environment.NewLine + Environment.NewLine;
                        }

如果有人能够在这里帮助我,我们将非常感激:D

1 个答案:

答案 0 :(得分:0)

使用Process.WaitForInputIdle()以便您知道其他进程已准备好输入,然后根据需要使用SendKeys,如果您确实需要等待它退出,可以调用Process.WaitForExit()

修改

用下面的行process.WaitForExit();替换,并使用您需要的键C更新

process.WaitForInputIdle();
SendKeys.SendWait("Your Key Strokes");
process.WaitForExit();