工作中有時需要啟動和停止windows service,有時候會出現服務處於stopping或者starting的狀態,但是,在services介面中,start service/stop service已經處於灰色不可操作狀態,用命令列的形式net start/stop servicename也無濟於事。停止服務的方法就是關掉這個進程,但是很多時候無法確定是哪個進程與之相關。在命令列中我們可以使用sc queryex servicename這個命令來獲得該服務的相關資訊。
For example,
Run 'sc queryex WebsenseDCAgent' in command prompt
The output is below,
SERVICE_NAME: WebsenseDCAgent
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x1d4c8
PID : 4488
FLAGS :
查看到此服務的進程號以後我們可以用命令 'taskkill /PID 4488 /F' 來強制結束此服務的進程. /F means 'kill forcely'.
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1S94I1K-0.png" width="545" height="608" />
過一會兒我們再查看服務的狀態它會自動再運行,OK大功告成
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1S94H554-1.png" width="544" height="425" />
補上hyy1988說的方法:就是 在 Service上點右鍵有個 Go to Process,會轉到這個Service依賴的進程上,Kill掉,完事。
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1S94L153-2.png" width="448" height="436" />
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1S94M634-3.png" width="448" height="544" />
sc功能很強大,具體可以參考下面的連結:http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sc.mspx?mfr=true