有2個PowerShell腳本在啓動時運行,1個在我的控制之下,另一個在我的控制之外。PowerShell:啓動進程的另一個實例已在運行
我們的兩個腳本都使用Start-Process。奇怪的問題是,如果我們兩個開始處理的的發生在同一時間執行,我從我的腳本以下錯誤:
Start-Process : This command cannot be run due to the error: An instance of the service is already running.
有沒有辦法,看看另一個「開始處理」已經運行?我知道「Get-Process」,但只顯示PowerShell正在運行,而不是當前運行的cmdlet。
我不贊成不使用啓動過程。
作爲一個臨時解決方法,我告訴我的腳本睡了60秒,但寧願知道何時開始另一個進程完成。
這裏是我的代碼:
$pw = ConvertTo-SecureString -AsPlainText -Force -String "myPassword"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "Administrator",$pw
$psArgList = "-ExecutionPolicy Bypass","-file"
$psArgList += $args
Start-Process powershell.exe -Wait -Credential $cred -ArgumentList $psArgList
這讓我擁有完全權限運行另一個PowerShell腳本:以管理員與ExecutionPolicy旁路。
我不太確定這是使用Start-Process作爲兩個會話嘗試同時運行服務的另一個會話的問題。你的啓動過程試圖做什麼?你能否顯示相關的代碼? – TheMadTechnician 2014-09-23 22:21:45
感謝您的評論。更新了帖子以包含我的代碼。 – Vippy 2014-09-23 22:35:33