Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.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# 调用EXE时无法执行waitforexit_C#_Powershell_Exe_Invoke Command - Fatal编程技术网

C# 调用EXE时无法执行waitforexit

C# 调用EXE时无法执行waitforexit,c#,powershell,exe,invoke-command,C#,Powershell,Exe,Invoke Command,我正在使用下面的代码运行EXE。EXE正确打开并正常运行。我面临两个问题 调用PowerShell.Invoke时是否存在类似于Process.WaitforExit的内容。一旦用户完成对EXE的操作并关闭该操作,则剩余的执行应继续 EXE的输出是System.Management.ManagementBaseObject。它应该包含可执行结果 如果我使用Process.Start运行EXE,我可以实现上述两个结果。输出也正常上升。请帮忙 using (Runspace runSpace = R

我正在使用下面的代码运行EXE。EXE正确打开并正常运行。我面临两个问题

调用PowerShell.Invoke时是否存在类似于Process.WaitforExit的内容。一旦用户完成对EXE的操作并关闭该操作,则剩余的执行应继续

EXE的输出是System.Management.ManagementBaseObject。它应该包含可执行结果

如果我使用Process.Start运行EXE,我可以实现上述两个结果。输出也正常上升。请帮忙

using (Runspace runSpace = RunspaceFactory.CreateRunspace())
{
    string remoteScriptPath="e:\shared\test.ex";
    string parameterString="p1";
    runSpace.Open();
    using (Pipeline pipeline = runSpace.CreatePipeline())
    {
        RunspaceInvoke invoke = new RunspaceInvoke();
        PowerShell ps = PowerShell.Create();
        ps.Runspace = runSpace;
        ps.AddCommand("invoke-wmimethod");
        ps.AddParameter("class", "Win32_Process");
        ps.AddParameter("name", "Create");
        if (string.IsNullOrEmpty(parameterString))
        {
            ps.AddParameter("argumentlist", remoteScriptPath);
        }
        else
        {                            
         ps.AddParameter("argumentlist", remoteScriptPath + " " + parameterString);
        }

        Collection<PSObject> psOutput = ps.Invoke();

        if (ps.Streams.Error.Count == 0)
        {
            string result="";

            foreach (PSObject psObject in psOutput)
            {
                if (psObject != null)
                {
                    result += psObject.BaseObject.ToString();
                    result += Environment.NewLine;
                }
            }
            return result;
        }

您已经有了C代码。。为什么必须从C使用Powershell来启动另一个应用程序。。为什么不使用.Net framework中内置的Process类,我听说您已经使用该类获得了预期的结果?我只想使用PowerShell在远程计算机上运行exe。您应该是提出问题的人,但让我问一个问题:您确定能够使用PowerShell远程处理启动交互式桌面应用程序吗?我从来没有试过。。但是如果它不能像你想象的那样工作,我也不会感到惊讶。。或者可能是我错了,或者可能是我仍然错误地理解了您的场景。您是否尝试过运行一些简单的操作,例如get位置,只是为了验证powershell运行空间是否正常工作?是的,运行空间正常工作。我能够使用上述代码打开EXE。我的要求是程序执行应该停止,直到EXE打开。一旦用户关闭EXE,程序将继续执行。希望我能澄清这个要求。