[英]Start Application on Remote machine and keep it running and powershell script should not wait for process to finish
遠程計算機上有一個名為Vesper.exe的應用程序。 我現在正在做的是使用Powershell會話遠程登錄到計算機。
要求 :需要在遠程計算機上啟動應用程序,並且在powershell腳本完成執行后,應用程序應保持運行
我嘗試了兩種方法,以下是摘要:
以下是powershell代碼:
# Create a new session on the remote machine with the above credentials
try {
$newsession = New-PSSession -ComputerName $loadvm -Credential $loadvm_credentials
Write-Host "Connected successfully..."
} catch [Exception] {
echo "Error while connecting to the remote machine", $_.Exception.GetType().FullName, $_.Exception.Message
exit 1
}
try {
Invoke-Command -Session $newsession -Scriptblock {
Write-Host "Cd'ing and starting Vesper on"
cd C:\vesper_cpt
Start-Process -file Vesper.exe -ArgumentList "-auto"
} -ErrorAction Stop
} catch [Exception] {
echo "Error while running the remote command", $_.Exception.GetType().FullName, $_.Exception.Message
Remove-PSSession $newsession
exit 1
}
Exit-PSSession
如何將二進制作為服務運行? 然后,Powershell將僅用於啟動/停止服務,這非常簡單。
您可以使用nssm輕松地將任何可執行文件轉換為服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.