SC命令(windows服務開啟/禁用)


原文鏈接地址:https://blog.csdn.net/cd520yy/article/details/30976131

sc.exe命令功能列表:  

  1.更改服務的啟動狀態(這是比較有用的一個功能)   

  2.刪除服務(除非對自己電腦的軟、硬件所需的服務比較清楚,否則不建議刪除任何系統服務,特別是基礎服務)  

  3.停止或啟動服務(功能上類似於net stop/start,但速度更快且能停止的服務更多)

  具體的命令格式如下:  

  修改服務啟動類型的命令行格式為(特別注意start=后面有一個空格)  

  sc config 服務名稱 start= demand(設置服務為手動啟動)   

  sc config 服務名稱 start= disabled(設置服務為禁用)   

  停止/啟動服務的命令行格式為   

  sc stop/start 服務名稱   

  注意:平時常接觸的都是服務的顯示名稱,而以上所指是服務名稱,都可以在控制面板->管理工具->服務里面,雙擊對應的服務來查詢。  

  先舉例說明一下具體的設置方法:   

  如設置遠程注冊表服務為手動其格式為   

  sc config RemoteRegistry start= demand   

  設為禁用的格式為:

  sc config RemoteRegistry start= disabled   

  停止服務則格式為:   

  sc stop RemoteRegistry   

  首先把自己所需設置的服務名稱查到之后,按照上面的格式做成批處理文件,重裝系統之后只要運行批處理文件即可。  

  以下是我的設置,以XpSp2為藍本,可比對所用的系統進行增刪和修改。注:未加入XpSp2的自動更新、安全中心、防火牆。 

  sc config Alerter start= demand   

  sc config TrkWks start= demand   

  sc config helpsvc start= demand   

  sc config policyAgent start= demand   

  sc config dmserver start= demand   

  sc config WmdmpmSn start= demand   

  sc config Spooler start= demand   

  sc config RemoteRegistry start= demand   

  sc config NtmsSvc start= demand   

  sc config seclogon start= demand   

  sc config Schedule start= demand   

  sc config WebClient start= demand   

  sc config W32Time start= demand   

  sc config WZCSVC start= demand

  sc config ERSvc start= demand   

  sc config Themes start= demand   

  sc config FastUserSwitchingCompatibility start= disabled   

  sc config Messenger start= disabled   

  sc config protectedStorage start= disabled

  sc config SSDpSRV start= disabled   

  sc config TermService start= disabled   

  sc config ShellHWDetection start= disabled   

  如果需要立即關閉服務也可把以下代碼跟在上面的代碼之后

  sc stop W32Time   

  sc stop ShellHWDetection   

  sc stop TrkWks

  sc stop helpsvc

  sc stop dmserver

  sc stop policyAgent   

  sc stop Spooler   

  sc stop RemoteRegistry   ;遠程修改注冊表

  sc stop seclogon   

  sc stop Schedule   

  sc stop WZCSVC

  sc stop ERSvc   

  sc stop Themes   

  sc stop FastUserSwitchingCompatibility   

  sc stop protectedStorage   

  sc stop SSDpSRV   

  sc stop WebClient   

  最后把修改好之后的代碼存為services.cmd,在以后進行服務設置時,直接運行事先保存好的批處理文件就可以做到事半功倍了。  

  看到這里,使用Win2000的朋友也不必失望,sc.exe這個命令行工具對Win2000同樣適用,可從裝有WinXp或者Win2003的機器里面拷貝sc.exe文件,與保存好的批處理文件放在一起,然后執行批處理文件即可。  

  對注冊表比較熟悉的朋友可能會想到用注冊表來設置服務的啟動類型,這也是一種可行的方法,本身卻有着內在不足。原因是服務啟動類型在注冊表中對應的鍵值較長且分散,進行整理不方便直觀且易錯漏,所以這種方法比較適用於無人值守的安裝時使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM