SC



롰Ѱװ豸ͨѶSC.exe йطĿϢʹ SC.exe Ժ͵Է򡣿ô洢עеķʱΪ̨ʱӦóSC.exe Ĳָķ񣬼ǰ״̬Ҳֹͣ񡣿ļòͬ SC.exe ԶرշСSC.exe ṩĹڡ塱Сߡеġ񡱡


й﷨뵥һ sc 


sc boot



ǷӦô洢Ϊϴ֪á


﷨



sc [ServerName]  boot [{bad|OK}]






ServerName
ָڵԶ̷ơƱͨõ (UNC) ʽ"\\myserver"Ҫڱ SC.exeԴ˲

[{bad|OK}]
ָǷǷӦô洢Ϊϴ֪á

/?ʾʾ







ķʾʹ sc boot 

sc boot ok
 sc boot bad 


sc config 



޸ע͡ƹݿеķֵ


﷨



sc [ServerName] config [ServiceName] [type= {own|share|kernel|filesys|rec|adapt|interact type= {own|share}}] [start= {boot|system|auto|demand|disabled}] [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|adapt|interact type= {own|share}}
ָ÷͡


ֵ
˵

own
ĽСִļĬá


share
ΪСһִļ


kernel



filesys
ļϵͳ


rec
ļϵͳʶʾʹõļϵͳ


adapt
ʾ̡ꡢӲ


interact
潻ãû롣 LocalSystem ʻСͱ type= own  type= shared磬 type= interact type= ownʹáʹ type= interact һЧ



start= {boot|system|auto|demand|disabled}
ָʼ͡


ֵ
˵

boot
ص豸


system
ںĳʼ豸

auto
ÿμʱû˵¼ʱԶʼķ

demand
ֶķûָstart=Ĭֵ

disabled
ķҪһõķ񣬰͸Ϊֵ



error= {normal|severe|critical|ignore}
Уʧܣָԡ


ֵ
˵

normal
¼󣬲ʾϢԻ֪ͨûʧܡĬá


severe
¼ڣµЧڼܹȴȻС


critical
¼ڣµЧϴ֪ʧܣҲʧܣ̾ͻԡֹͣ


ignore
Ѽ¼¼󳬳¼־ķΧٸûʾ



binpath= BinaryPathName
ָһļ·

group= LoadOrderGroup
ָһ÷ΪгԱбעе HKLM\System\CurrentControlSet\Control\ServiceGroupOrder СĬΪֵ

tag= {yes | no}
ָǷڡCreateServiceл TagIDǽڸϵͳ

depend= dependencies
ָڴ֮ǰķǰб (/) 뿪֡

obj= {AccountName|ObjectName}
ָһеķ˻ָһе Windows ĬΪ LocalSystem

displayname= DisplayName
ָһûΪûʶѺõġơ磬һǶûûа wuauservʾǡԶ¡

password:password
ָһ롣ʹһ LocalSystem ʻǱġ

/?ʾʾ




ע


ֵ֮ûпո񣬣磬 type= own,  type=ownʧܡ






淶ʾʹ sc config 

sc config NewService binpath= "ntsd -d c:\windows\system32\NewServ.exe" 


sc continue



Ϊ˼ͣķҪһ CONTINUE 


﷨



sc [ServerName]  continue [ServiceName]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

/?ʾʾ




ע


 ʹ continue ͣķ
    






ķʾʹ sc continue 

sc continue tapisrv 


sc control



͸CONTROL B


﷨



sc [ServerName] control [ServiceName]  [{paramchange|netbindadd|netbindremove|netbindenable|netbinddisable|UserDefinedControlB}]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

{paramchange|netbindadd|netbindremove|netbindenable|netbinddisable|UserDefinedControlB}
ָҪ͵Ŀơ

/?ʾʾ






sc create



Ϊע͡ƹдڡ


﷨



sc [ServerName] create [ServiceName] [type= {own|share|kernel|filesys|rec|adapt|interact type= {own|share}}] [start= {boot|system|auto|demand|disabled}] [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|adapt|interact type= {own|share}}
ָ÷͡ĬΪ type= own

ֵ
˵

own
ĽСִļĬá


share
ΪСһִļ


kernel



filesys
ļϵͳ


rec
ļϵͳʶڼʹõļϵͳ


interact
潻ãû롣 LocalSystem ʻСͱ type= own  type= shared磬 type= interact type= ownʹáʹ type= interact һЧ



start= {boot|system|auto|demand|disabled}
ָʼ͡Ĭϵʼ start= demand

boot
ص豸


system
ںĳʼ豸

auto
ÿμʱû˵¼ʱԶʼķ

demand
ֶķûָstart=Ĭֵ

disabled
ķҪһõķ񣬰͸Ϊֵ



error= {normal|severe|critical|ignore}
УʧܣָԡĬΪ ascii

normal
¼󣬲ʾϢԻ֪ͨûʧܡĬá


severe
¼ڣµЧڼܹȴȻС


critical
¼ڣµЧϴ֪ʧܣҲʧܣ̾ͻԡֹͣ


ignore
Ѽ¼¼󳬳¼־ķΧٸûʾ



binpath= BinaryPathName
ָһļ·binpath= ûĬֵҪַ

group= LoadOrderGroup
ָһ÷ΪгԱбעе HKLM\System\CurrentControlSet\Control\ServiceGroupOrder СĬΪֵ

/hidden:{yes | no}
ָǷڡCreateServiceл TagIDǽڸϵͳ

depend= dependencies
ָҪڴ֮ǰķǰб (/) 뿪֡

obj= {AccountName|ObjectName}
ָһеķ˻ָһе Windows 

displayname= DisplayName
ָûʶѺơ

password:password
ָһ롣ʹõĲ LocalSystem ʻǱġ

/?ʾʾ




ע


ֵ֮ûпո񣬣磬 type= own,  type=ownʧܡ






ķʾʹ sc create 

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

sc delete



עɾлһһ÷Ĵ򿪾ôΪɾǸ÷


﷨



sc [ServerName] delete [ServiceName]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

/?ʾʾ



ע


	ʹáӻɾɾ DHCPDNS κõĲϵͳ񡣡ӻɾ򡱲ֻɾ÷עһж÷ɾеĿݷʽ
	






ķʾʹ sc delete 

sc delete newserv 

sc description



÷ַ


﷨



sc [ServerName] description [ServiceName]  [Description]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

˵
Ϊָָûַָ򲻻޸ĸ÷԰ڷеַûơ

/?ʾʾ







ķʾʹ sc description 

sc description newserv "Runs quality of service control." 


sc enumdepend



гָֻܹеķ


﷨



sc [ServerName] enumdepend [ServiceName] [BufferSize]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

BufferSize
ֽΪλָöٻĴСĬֵΪ 1024 ֽڡ

/?ʾʾ




ע


	enumdepend ֻᲿ񣬲ָĶ⻺СضϣиòָĻС






ķʾʹ sc enumdepend 

sc enumdepend rpcss 5690
 sc enumdepend tapisrv 

sc failure



ָʧʱҪȡĲ


﷨



sc [ServerName] failure [ServiceName] [reset= ErrorFreePeriod] [reboot= BroadcastMessage] [command= CommandLine] [actions= FailureActionsAndDelayTime]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

reset= ErrorFreePeriod
ָûʧܵڳȣλΪ룩˺ʧܼӦΪ 0 actions= ʹá

reboot= BroadcastMessage
ָʧʱҪ㲥Ϣ

command= CommandLine
ָʧʱҪеСйʧʱ VBS ļϢġע͡

actions= FailureActionsAndDelayTime
ָʧܲӳʱ䣨λΪ룩б (/) вЧrunrestart  reboot˲ reset= ʹáʧʱȡʹ actions= ""

/?ʾʾ




ע


	еķʧѡһЩΪ񼯵һС
	Ҫʧʱļָ cmd.exe Drive:\FileName.bat Ϊ command= Ĳ Drive:\FileName.bat ļĺϸơ	
	Ҫʧʱ VBS ļָ cscript drive:\myscript.vbs Ϊ command= Ĳ drive:\myscript.vbs ǽűļĺϸơ
	ԽֲͬĲָΪ actions= ĲǽڷĵһΡڶΡʧʱʹá
ֵ֮ûпո񣬣磬 type= own type=ownʧܡ






ķʾʹ sc failure 

sc failure msftpsvc reset= 30 actions= restart/5000
 sc failure dfs reset= 60 command= c:\windows\services\restart_dfs.exe actions= run/5000
 sc failure dfs reset= 60 actions= reboot/30000
 sc failure dfs reset= 60 reboot= "The Distributed File System service has failed. Because of this, the computer will reboot in 30 seconds."  actions= reboot/30000
 sc failure myservice reset= 3600 reboot= "MyService crashed -- rebooting machine" command= "%windir%\MyServiceRecovery.exe" actions= restart/5000/run/10000/reboot/60000 

sc getdisplayname



ضʾơ


﷨



sc [ServerName] getdisplayname [ServiceName] [BufferSize]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

BufferSize
ָСֽΪλĬֵΪ 1024 ֽڡ

/?ʾʾ







ķʾʹ sc getdisplayname 

sc getdisplayname clipsrv
 sc getdisplayname tapisrv
 sc getdisplayname sharedaccess 

sc getkeyname



ʹضʾΪļ


﷨



sc [ServerName] getkeyname [ServiceDisplayName]  [BufferSize]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceDisplayName
ָʾơ

BufferSize
ָСֽΪλĬֵΪ 1024 ֽڡ

/?ʾʾ




ע


 ServiceDisplayName ոʹŽı磬"Service Display Name"






ķʾʹ sc getkeyname 

sc getkeyname "remote procedure call (rpc)"
 sc getkeyname "internet connection sharing"
 sc getkeyname clipbook 

sc interrogate



һ INTERROGATE 


﷨



sc [ServerName] interrogate [ServiceName]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

/?ʾʾ




ע


ʹáƹ INTERROGATE ᵼ¸÷ʹáƹ״̬






ķʾʹ sc interrogate 

sc interrogate sharedaccess
 sc interrogate rpcss 

sc lock



ƹݿ⡣


﷨



sc [ServerName] lock






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

/?ʾʾ




ע


ƹݿֹκη
Ҫȷֹ֮ͣ󲻻ʹܸŵĽһЩ磬ɾ񣩡
ʹ lock ƹݿ⣬Ȼͨ u ʹݿҲԴݿĽйرոý̡






ķʾʹsc lock 

sc lock 

sc pause



 PAUSE 󵽷


﷨



sc [ServerName] pause [ServiceName]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

/?ʾʾ




ע


ֹ֮ǰʹ pause ͣ
еķܹͣ
ͣʱеķִͬĲһЩΪеĿͻ˷񣬵µĿͻˡĻֹпͻ˵ķ񣬶ҲµĿͻˡ	






ķʾʹsc pause 

sc pause tapisrv 

sc qc



ѯϢ


﷨



sc [ServerName] qc [ServiceName] [BufferSize]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

BufferSize
ָСֽΪλĬֵΪ 1024 ֽڡ

/?ʾʾ




ע


 qc ʾйطϢSERVICE_NAMEעеӼTYPEERROR_CONTROLBINARY_PATH_NAMELOAD_ORDER_GROUPTADISPLAY_NAMEDEPENDENCIES  SERVICE_START_NAME


Աʹ SC ȷһĶƣǷһ̣м


sc qc ServiceName


SC ڽ Microsoft ̨ (MMC) еķ롰ϵͳеĽƥ Services.exeô̡


Services.exe еķΪϵͳԴΪ Windows  Win32 񱻱дΪ Services.exe ̡ЩΪĽڡϵͳ֮СSvchost.exe ҲˣǺܶķ̡


Ϊ Win32 ҲΪ̣ԲΪÿһ Win32 񴴽һ̡SC ЩϢǣһ̣ôڷʱϵͳл̡



Ϊ SC  Windows е Services.exe ȣṩ˸Ϊϸ׼ȷġڷϢԶڷ񿪷Ա˵ SC ôServices.exe ȷСֹͣͣЩ߶ƽеѵԳѾ㹻ṩĹڿķϢȴʹ⡣磬һķ񲻹ʵʾΪ


SC ִж Windows Ӧñ̽ӿ (API) ĵáָͨЩΪ


ʹ SCԲѯ״̬洢״̬ṹеֵServices.exe ṩ״̬ SC ʾ˾ȷķ״̬Լµļ͵ȴʾԽԹߣԭڳֹͣӦ֮ǰʼ˶ԶSC ҲָԶ̼ԱԶ̼ϵ÷ API 鿴״̬ṹ







ķʾʹ sc qc 

sc qc \\myserver newsrvice
 sc qc rpcss 248 

sc qdescription



ʾַ


﷨



sc [ServerName] qdescription [ServiceName] [BufferSize]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

BufferSize
ָСֽΪλĬֵΪ 1024 ֽڡ

/?ʾʾ







ķʾʹ sc qdescription 

sc qdescription rpcss
 sc qdescription rpcss 138 

sc qfailure



ʾָʧʱҪִеĲ


﷨



sc [ServerName] qfailure [ServiceName] [BufferSize]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

BufferSize
ָСֽΪλĬֵΪ 1024 ֽڡ

/?ʾʾ




ע


 qfailure ʾйطϢSERVICE_NAMEעеӼRESET_PERIODREBOOT_MESSAGECOMMAND_LINE  FAILURE_ACTIONS






ķʾʹ sc qfailure 

sc qfailure rpcss
 sc qfailure rpcss 20 

sc query



úʾָķͻ͵Ϣ


﷨



sc [ServerName] query [ServiceName] [type= {driver|service|all}] [type= {own|share|interact|kernel|filesys|rec|adapt}] [state= {active|inactive|all}] [bufsize= BufferSize] [ri= ResumeIndex] [group= GroupName]







ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ query  query ʹã ServerName

type= {driver|service|all}
ָҪгݡĬΪ service


ֵ
˵


driver
ָҪöٵ


service
ָҪöٵķ


all
ָҪöٵͷ



type= {own|share|interact|kernel|filesys|rec|adapt}
ָҪöٵķͻ


ֵ
˵


own
ĽСִļĬá


share
ΪСһִļ


interact
潻ãû롣 LocalSystem ʻС


kernel



filesys
ļϵͳ



state= {active|inactive|all}
ָöٵķѿʼ״̬Ĭ״̬active

ֵ
˵


active
ָеļ


inactive
ָֹͣͣķ

all
ָз



bufsize= BufferSize
ֽΪλָöٻĴСĬϴСΪ 1024 ֽڡӲѯصʾ 1024 ֽʱöٻĴС

ri= ResumeIndex
ָʼöٵĬֵΪ 0ڲѯصϢĬϻܹʾĴСʱ bufsize= ʹ

group= GroupName
ָöٵķ顣ĬΪ顣

/?ʾʾ




ע


ֵ֮ûпո񣬣磬 type= own type=ownʧܡ
query ʾ¹ڷϢSERVICE_NAME עеӼTYPESTATEҲǲõ״̬WIN32_EXIT_BSERVICE_EXIT_BCHECKPOINT  WAIT_HINT
ĳЩ£type=ʹΡtype=ĵһγָǷѯЩtype=ĵڶγָһɡcreateһСѯΧ͡
 query ʾöٻĴСʱʾµϢ

Enum:ݳ 79 Ҫ 1822 ֽ

Ҫʾʣ query Ϣ query bufsize= Ϊֽ ri= Ϊָ磬мָʾʣ

sc query bufsize= 1822 ri= 79






ķʾʹ sc query 

sc query
 sc query messenger
 sc query type= driver
 sc query type= service
 sc query state= all
 sc query bufsize= 50
 sc query ri= 14
 sc query type= service type= interact
 sc query type= driver group= ndis 

sc queryex



úʾڷͻ͵չϢ


﷨



sc [ServerName] queryex [type= {driver|service|all}] [type= {own|share|interact|kernel|filesys|rec|adapt}] [state= {active|inactive|all}] [bufsize= BufferSize] [ri= ResumeIndex] [group= GroupName]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ queryex  ServerName ֮κ queryex ʹá

type= {driver|service|all}
ָҪгݡĬΪ service


ֵ
˵

driver
ָҪöٵ.


service
ָҪöٵķ


all
ָҪöٵͷ



type= {own|share|interact|kernel|filesys|rec|adapt}
ָҪöٵķͻ

ֵ
˵


own
ĽСִļĬá


share
ΪСһִļ


interact
潻ãû롣 LocalSystem ʻС


kernel



filesys
ļϵͳ



state= {active|inactive|all}
ָöٵķѿʼ״̬Ĭ״̬ active

ֵ
˵


active
ָеļ


inactive
ָֹͣͣķ

all
ָз



bufsize= BufferSize
ֽΪλָöٻĴСĬϴСΪ 1024 ֽڡ

ri= ResumeIndex
ָʼöٵĬֵΪ 0

group= GroupName
ָöٵķ顣ĬΪ顣

/?ʾʾ




ע


ֵ֮ûпո񣬣磬 type= own type=ownʧܡ
queryex ʾйطϢSERVICE_NAMEעеӼTYPESTATEҲǲõ״̬WIN32_EXIT_BSERVICE_EXIT_BCHECKPOINTWAIT_HINTPID  FLAGS
ĳЩ£type=ʹΡtype=ĵһγָǷѯЩtype=ĵڶγָһɡcreateһСѯΧ͡
 queryex ʾöٻСʱʾµϢ

Enum:ݳ 75 Ҫ 2130 ֽ

Ҫʾ queryex ʣϢ queryex bufsize= Ϊֽ ri= Ϊָ磬мָʾʣ

sc queryex bufsize= 2130 ri= 75






ķʾʹ sc queryex 

sc queryex messenger
 sc queryex group= "" 

sc querylock



ѯʾƹݿϢ


﷨



sc [ServerName] querylock






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲
/?ʾʾ
 

sc sdset



ʹáԡ (SDDL) ÷İȫ


﷨



sc [ServerName] sdset ServiceName ServiceSecurityDescriptor






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

ServiceSecurityDescriptor
 SDDL ָ

/?ʾʾ




ע


й SDDL Ϣ MSDN ֪ʶеġȫԡ(http://www.microsoft.com/)
 

sc sdshow



ʹ SDDL ʾİȫ


﷨



sc [ServerName] sdshow ServiceName






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

/?ʾʾ




ע


й SDDL Ϣ MSDN ֪ʶ еġȫԡ(http://www.microsoft.com/)







sc sdshow rpcss 

sc start



еķ


﷨



sc [ServerName] start ServiceName [ServiceArguments]






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

ServiceArguments
ָݸҪķķ

/?ʾʾ







ķʾʹ sc start 

sc start tapisrv 

sc stop



 STOP 


﷨



sc  [ServerName] stop ServiceName






ServerName
ָڵԶ̷ơƱʹ UNC ʽ ("\\myserver")Ҫڱ SC.exeԴ˲

ServiceName
ָ getkeyname صķ

/?ʾʾ




ע


еķ񶼿Աֹͣ






ķʾʹ sc stop 

sc stop tapisrv 


ע




