標籤:使用 io art ar div line 管理 window
有一種C#命令列console程式,為了能看到console台的輸出所以不能做成服務。為了防止這些程式自己死掉,使用powershell監控程式並重啟
#利用程式名來進行重啟
if (!(get-process | where-object {$_.mainwindowtitle -eq ‘管理員: "tsiphone"‘}))
{ cd C:\lengshan
C:\lengshan\tsiphone.bat }
#如果是在命令列參數裡面執行的話,那就應該適應 gwmic 來獲得comandline的內容來進行區分了#因為正常情況下,get-process的操作是沒有comandline這個屬性的
if (!(Get-WmiObject win32_process | where {$_.CommandLine -eq "`"C:\php\php.exe`" `"C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\deamon\igetui_deamon.php`""}))
{ cmd /c start "" "C:\lengshan\tsgetui.bat" }
#將命令列做成bat,之後利用powershell判斷進程是否存在,不存在的話,先結束對應的cmd進程,之後再利用start開啟新的cmd視窗來啟動php進程
if (!(Get-WmiObject win32_process | where {$_.CommandLine -eq "`"c:\php\php.exe`" `"C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\deamon\apns_deamon.php`""}))
{ get-process cmd |where {$_.MainWindowTitle -eq "管理員: `"tsiphone`""} | stop-process
cmd /c start "" "C:\lengshan\tsiphone.bat"}