2016-10-11 21 views
0

我正在RDP環境中進行測試,並且在Windows Server 2008 R2上有受限用戶權限。該腳本使用Sapien PowerShell工作室構建爲PowerShell Forms V3(Win64)。因此我無法調試程序,以及應用程序如何放置在每個用戶桌面上。我可以在本地進行調試和運行,一切正常。PowerShell窗體在腳本的結尾處停止響應

我把數據從文本框中發送到函數來完成所有重要的位。

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 [email protected]", "Status") 
} 

回答

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 [email protected]", "Status")
在你缺少.NET綁定到PowerShell的同時,[CmdletBinding()]

現在我沒有得到太多的experiance與Sapien的PowerShell的工作室,但我不記得有與.NET中的綁定問題當在PowerShell Studio中編譯爲EXE時。

沒有看PowerShell Transcript或PowerShell事件日誌,如果這是您看到腳本失敗/崩潰的地方,我不會感到驚訝。
您是否考慮過PowerShell原生選項? $ErrorStart-Transcript在PowerShell中V3 +(你的WMF 3.0?),甚至try { }; catch { }

在腳本的開始使用$Error.Clear()然後你可以調用$Error日誌,查看詳細信息,讓我們知道,如果你仍然獲得後需要幫助內置錯誤記錄數據。

祝你好運:)

+0

感謝您的回覆jaradsc,你可以讓我知道你將如何去添加.NET綁定到PowerShell嗎? – Bridger

+0

嗨布里傑,這裏有一個很好的審查這裏https://technet.microsoft.com/en-us/library/hh847872.aspx,還有更多,如果你谷歌它。但是,如果您想調用C#(.cs)代碼或文件,使用.NET參考或在PowerShell中使用(x)AML,這是很常見的。您對Windows窗體消息框的引用使用的是Windows DLL,因此需要導入到PowerShell中,其他選項是使用COM對象參考(如「New-Object -ComObject Wscript.Shell」)作爲消息框。 – jaradsc