![](/img/trans.png)
[英]When executing a batch file from c# with the window hidden, programs that are executed by the batch file won't start
[英]Batch file won`t start program when launched from windows service
我創建了一個批處理文件,以在特定服務停止時運行。 批處理文件應停止運行相關軟件,重新啟動某些服務(停止/啟動),然后重新啟動軟件。
一個簡單的代碼:
@echo off
Taskkill /F /IM program1.exe
Taskkill /F /IM program2.exe
timeout /t 5
net stop service1
net stop service2 && net start service2
net start service3
timeout /t 2
start C:/path/program1.exe
start C:/path/program2.exe
設置服務以在第一次失敗時將批處理文件作為恢復運行。 通過快捷方式鏈接批處理文件,以便能夠以管理員身份運行它。
當直接運行批處理文件時,此方法非常有效,但是當通過服務恢復執行批處理文件時,軟件啟動失敗。 有人知道什么地方可能出問題嗎?
在某些情況下, timeout /t 5
可能會引起麻煩。 嘗試將其替換為PING -n 6 127.0.0.1 > NUL
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.