使用命令行啓動服務

使用命令行啓動服務
在cmd下可有兩種方法打開,net和sc,net用於打開沒有被禁用的服務,語法是:
net start 服務名                         啓動 net start 服務名
                                                 中止 net stop 服務名
net stop 服務名
用sc可打開被禁用的服務,語法是:
sc config 服務名 start= demand     //手動
sc condig 服務名 start= auto       //自動
sc config 服務名 start= disabled //禁用
sc start 服務名
sc stop   服務名
注:1)服務名不必定是你在服務面板看到的那個名,例如,你要打開被禁用的telnet服務,sc config telnet start= auto,報錯:[SC] OpenService FAILED 1060,由於telnet的服務名不是telnet而是tlntsvr, sc config tlntsvr start= auto     就OK了,在服務面板裏查看telnet屬性,從可執行文件的路徑裏可看到服務程序名,即命令中的服務名。   2)start=後面有空格,少了就有錯
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文件,與保存好的批處理文件放在一塊兒,而後執行批處理文件便可。  
  對註冊表比較熟悉的朋友可能會想到用註冊表來設置服務的啓動類型,這也是一種可行的方法,自己卻有着內在不足。緣由是服務啓動類型在註冊表中對應的鍵值較長且分散,進行整理不方便直觀且易錯漏,因此這種方法比較適用於無人值守的安裝時使用。
使用案例:
在命令行下啓動自動更新服務:
C:\>sc config wuauserv start= auto
[SC] ChangeServiceConfig SUCCESS
C:\>sc start wuauserv
SERVICE_NAME: wuauserv
         TYPE               : 20   WIN32_SHARE_PROCESS
         STATE               : 2   START_PENDING
                                 (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
         WIN32_EXIT_CODE     : 0   (0x0)
         SERVICE_EXIT_CODE   : 0   (0x0)
         CHECKPOINT         : 0x0
         WAIT_HINT           : 0x7d0
         PID                 : 1156
         FLAGS               :
C:\>
使用命令行啓動服務
在cmd下可有兩種方法打開,net和sc,net用於打開沒有被禁用的服務,語法是:
net start 服務名                         啓動 net start 服務名
                                                 中止 net stop 服務名
net stop 服務名
用sc可打開被禁用的服務,語法是:
sc config 服務名 start= demand     //手動
sc condig 服務名 start= auto       //自動
sc config 服務名 start= disabled //禁用
sc start 服務名
sc stop   服務名
注:1)服務名不必定是你在服務面板看到的那個名,例如,你要打開被禁用的telnet服務,sc config telnet start= auto,報錯:[SC] OpenService FAILED 1060,由於telnet的服務名不是telnet而是tlntsvr, sc config tlntsvr start= auto     就OK了,在服務面板裏查看telnet屬性,從可執行文件的路徑裏可看到服務程序名,即命令中的服務名。   2)start=後面有空格,少了就有錯
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文件,與保存好的批處理文件放在一塊兒,而後執行批處理文件便可。  
  對註冊表比較熟悉的朋友可能會想到用註冊表來設置服務的啓動類型,這也是一種可行的方法,自己卻有着內在不足。緣由是服務啓動類型在註冊表中對應的鍵值較長且分散,進行整理不方便直觀且易錯漏,因此這種方法比較適用於無人值守的安裝時使用。
使用案例:
在命令行下啓動自動更新服務:
C:\>sc config wuauserv start= auto
[SC] ChangeServiceConfig SUCCESS
C:\>sc start wuauserv
SERVICE_NAME: wuauserv
         TYPE               : 20   WIN32_SHARE_PROCESS
         STATE               : 2   START_PENDING
                                 (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
         WIN32_EXIT_CODE     : 0   (0x0)
         SERVICE_EXIT_CODE   : 0   (0x0)
         CHECKPOINT         : 0x0
         WAIT_HINT           : 0x7d0
         PID                 : 1156
         FLAGS               :
C:\
相關文章
相關標籤/搜索