sc.exe create

在登錄和服務控制管理員資料庫中建立服務的子機碼和項目。

語法

sc.exe [<servername>] create [<servicename>] [type= {own | share | kernel | filesys | rec | interact type= {own | share}}] [start= {boot | system | auto | demand | disabled | delayed-auto}] [error= {normal | severe | critical | ignore}] [binpath= <binarypathname>] [group= <loadordergroup>] [tag= {yes | no}] [depend= <dependencies>] [obj= {<accountname> | <objectname>}] [displayname= <displayname>] [password= <password>]

參數

參數 描述
<servername> 指定服務所在遠端伺服器的名稱。 名稱必須使用通用命名慣例 (UNC) 格式 (例如 \myserver)。 若要在本機執行 SC.exe,請勿使用此參數。
<servicename> 指定 getkeyname 作業所傳回的服務名稱。
type= {own | share | kernel | filesys | rec | interact type= {own | share}} 指定服務類型。 選項包括:
  • own - 指定在其本身處理序中執行的服務。 它不會與其他服務共用可執行檔。 這是預設值。
  • share - 指定以共用處理序的形式執行的服務。 它會與其他服務共用可執行檔。
  • kernel - 指定驅動程式。
  • filesys - 指定檔案系統驅動程式。
  • rec - 指定可識別電腦上所用檔案系統之檔案系統辨識的驅動程式。
  • interact - 指定可與桌面互動的服務,接收使用者輸入。 互動式服務必須在 LocalSystem 帳戶下執行。 此型別必須與 type= owntype= share 搭配使用 (例如 type= interacttype= own)。 單獨使用 type=interact 會產生錯誤。
start= {boot | system | auto | demand | disabled | delayed-auto} 指定服務的啟動類型。 選項包括:
  • boot - 指定開機載入器所載入的裝置驅動程式。
  • system - 指定在核心初始化期間啟動的裝置驅動程式。
  • auto - 指定每次電腦重新啟動並執行時自動啟動的服務,即使無人登入電腦也一樣。
  • demand - 指定必須手動啟動的服務。 如果未指定 start=,則此為預設值。
  • disabled - 指定無法啟動的服務。 若要啟動停用的服務,請將啟動類型變更為一些其他值。
  • delayed-auto - 指定在啟動其他自動服務之後自動啟動的服務。
error= {normal | severe | critical | ignore} 如果啟動電腦時服務無法啟動,則指定錯誤的嚴重性。 選項包括:
  • normal - 指定記錄錯誤,並顯示訊息方塊,通知使用者服務無法啟動。 啟動將會繼續。 這是預設設定。
  • severe - 指定記錄錯誤 (可能的話)。 電腦會嘗試使用最後已知的良好組態重新啟動。 這可能會使電腦能夠重新啟動,但服務可能仍無法執行。
  • critical - 指定記錄錯誤 (可能的話)。 電腦會嘗試使用最後已知的良好組態重新啟動。 如果最後已知的良好組態失敗,啟動也會失敗,而開機程序會停止並出現停止錯誤。
  • ignore - 指定記錄錯誤並繼續啟動。 除了在事件記錄檔中記錄錯誤,不會通知使用者。
binpath= <binarypathname> 指定服務二進位檔的路徑。 binpath= 沒有預設值,而且必須提供此字串。
group= <loadordergroup> 指定此服務所屬群組的名稱。 群組清單會儲存在登錄的 HKLM\System\CurrentControlSet\Control\ServiceGroupOrder 子機碼中。 預設值為 null。
tag= {yes | no} 指定是否要從 CreateService 呼叫取得 TagID。 標記僅用於開機啟動和系統啟動驅動程式。
depend= <dependencies> 指定必須在此服務之前啟動的服務或群組名稱。 名稱會以正斜線 (/) 分隔。
obj= {<accountname> | <objectname>} 指定執行服務之帳戶的名稱,或指定驅動程式執行所在的 Windows 驅動程式物件名稱。 預設設定為 LocalSystem
displayname= <displayname> 指定易記名稱,以識別使用者介面程式中的服務。 例如,一個特定服務的子機碼名稱是 wuauserv,有比較易記的顯示名稱:自動更新。
password= <password> 指定密碼。 如果使用 LocalSystem 帳戶以外的帳戶,則此為必要項目。
/? 在命令提示字元顯示說明。

備註

  • 每個命令列選項 (parameter) 都必須包含等號作為選項名稱的一部分。

  • 選項與其值之間需要空格 (例如 type= own。 如果省略空間,則作業會失敗。

範例

若要建立並註冊 NewService 服務的新二進位路徑,請輸入:

sc.exe \\myserver create NewService binpath= c:\windows\system32\NewServ.exe
sc.exe create NewService binpath= c:\windows\system32\NewServ.exe type= share start= auto depend= +TDI NetBIOS

若要深入了解 sc.exe 命令,請參閱 SC 命令