Powershell表单在脚本的近端停止响应

时间:2016-10-11 23:06:43

标签: windows powershell

我在具有Windows Server 2008 R2上受限用户权限的RDP环境中进行测试。该脚本使用Sapien PowerShell工作室构建为PowerShell Forms V3(Win64)。我无法调试该程序,以及如何将应用程序放在每个用户桌面上。我可以在本地调试和运行,一切都很好。

我从文本框中拉出数据,将其发送给函数以完成所有重要的位。

GoTo_Run将其发送到Get_Credentials,其中(恰当地命名)获取我需要的用户凭据。我认为服务器在处理循环时遇到了问题,或者只是很慢,所以我添加了暂停以帮助事情赶上来。我不相信是这样的。如果Explorer ++没有运行,则表示凭据未经正确授权。当它打开时,它会等待Exp ++关闭然后打开并告诉他们他们所做的事情已被记录。

代码到达explorer ++正在运行的部分,然后从那里我不知道它死在哪里。当我退出Exp ++时,我没有收到脚本末尾的最后一个消息框,myexe.exe(总体脚本的​​名称)已经停止响应。

我已经通过以下链接查看了Sapien论坛:

https://www.sapien.com/forums/viewtopic.php?t=2339

https://www.sapien.com/blog/2011/07/15/primalforms-2011-creating-responsive-loops/

https://www.sapien.com/blog/2012/05/16/powershell-studio-creating-responsive-forms/

相关守则:

$buttonENTER_Click = {
    $newuser = $username.Text
    $newpass = $password.Text

    GoTo_Run $newpass $newuser
}

function GoTo_Run($newuser, $newpass)
{
    Get_Credentials $newuser $newpass
    Start-Sleep -Milliseconds 300
    $exp = Get-Process Explorer++ -ErrorAction SilentlyContinue

    if(-not $exp)
    {
        Start-Process '\\this\isthe\filepath'
        Start-Process '\\this\isthe\filepatheroonie'
    }
    while (get-process | ?{ $_.path -eq "\\the\file\path\for\explorer++" })
    {
        Start-Sleep -Milliseconds 1000
    }
    [System.Windows.Forms.MessageBox]::Show("Any Changes made have been recorded. If you have any issues or would like something added please email myemail@myemail.edugovorg", "Status")
}

1 个答案:

答案 0 :(得分:1)

您的代码中有以下.NET行[System.Windows.Forms.MessageBox]::Show("Any Changes made have been recorded. If you have any issues or would like something added please email myemail@myemail.edugovorg", "Status")
与此同时,您缺少.NET绑定到PowerShell,[CmdletBinding()]

现在我对Sapien PowerShell Studio没有多少经验,但我确实记得在PowerShell Studio中编译EXE时遇到.NET Binding的问题。

如果没有查看PowerShell脚本或PowerShell事件日志,如果您看到脚本失败/崩溃,那么我不会感到惊讶。
您是否考虑过PowerShell原生选项? $ErrorStart-Transcript以及PowerShell v3 +(您的WMF 3.0?)甚至try { }; catch { }

在脚本开头使用$Error.Clear(),然后您可以调用$Error日志来查看更多信息,如果您在获取内置错误日志记录数据后仍需要帮助,请告诉我们。

祝你好运:)