Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c等待已启动进程的对话框关闭_C#_Ssh_Process_Dialog_Pageant - Fatal编程技术网

C# c等待已启动进程的对话框关闭

C# c等待已启动进程的对话框关闭,c#,ssh,process,dialog,pageant,C#,Ssh,Process,Dialog,Pageant,如何等待阻止程序,直到上一个启动进程的特定对话框关闭 我正在启动pageant.exe以加载ssh密钥。选美比赛是从班级进程开始的。这个很好用 我的ssh密钥有一个密码短语。所以我的主程序/进程这一个启动了这个进程必须等到用户输入ssh密钥密码 我知道如何等待,但不知道如何使用c: 如果pageant请求密码短语,则会出现一个对话框。因此,我的主程序/进程可以等待密码短语对话框关闭。在c语言中可以这样做吗 我是从你那里得到这个主意的 编辑:找到解决方案 // wait till passphra

如何等待阻止程序,直到上一个启动进程的特定对话框关闭

我正在启动pageant.exe以加载ssh密钥。选美比赛是从班级进程开始的。这个很好用

我的ssh密钥有一个密码短语。所以我的主程序/进程这一个启动了这个进程必须等到用户输入ssh密钥密码

我知道如何等待,但不知道如何使用c: 如果pageant请求密码短语,则会出现一个对话框。因此,我的主程序/进程可以等待密码短语对话框关闭。在c语言中可以这样做吗

我是从你那里得到这个主意的

编辑:找到解决方案

// wait till passphrase dialog closes
if(WaitForProcessWindow(cPageantWindowName))
{ // if dialog / process existed check if passphrase was correct
    do
    { // if passphrase is wrong, the passphrase dialog is reopened
        Thread.Sleep(1000); // wait till correct passphrase is entered
        } while (WaitForProcessWindow(cPageantWindowName));
    }
}

private static bool WaitForProcessWindow(string pProcessWindowName)
{
    Process ProcessWindow = null;
    Process[] ProcessList;
    bool ProcessExists = false; // false is returned if process is never found


    do
    {
        ProcessList = Process.GetProcesses();
        ProcessWindow = null;
        foreach (Process Process in ProcessList)
        { // check all running processes with a main window title
            if (!String.IsNullOrEmpty(Process.MainWindowTitle))
            {
                if (Process.MainWindowTitle.Contains(pProcessWindowName))
                {
                    ProcessWindow = Process;
                    ProcessExists = true;
                }
            }
        }
        Thread.Sleep(100); // save cpu
    } while (ProcessWindow != null); // loop as long as this window is found
    return ProcessExists;
}

这可能会帮助你,但不会给你完全的控制权。我不熟悉选美比赛,所以我不确定它是否一直在后台运行。但如果程序自动关闭,您可以在应用程序中执行此操作

因此,您可以在循环中检查Pageant应用程序是否打开,一旦打开,您将执行一些代码,一旦关闭,您将再次启用该程序

在后台工作程序中执行此代码

    //Lets look from here if pageant is open or not. 

    while(true)
    {
        if (Process.GetProcessesByName("pageant").Length >= 1)
        {
             //block your controls or whatsoever.
             break;
        }
    }

    //pageant is open 

    while(true)
    {
         if (!Process.GetProcessesByName("pageant").Length >= 1)
         {
             //enable controls again
             break;
         }
    }

    //close thread

我们通常不会在这里为您将Perl脚本转换为c。此外,在这里检查有趣的事实可能有助于检查进程是否正在运行,而不是对话框是否打开。加上它最大限度的CPU