windows中,net
与 sc
这两个命令都可以用来开启或者关闭某个服务。
例如 net start mysql
, net stop mysql
, sc start mysql
, sc stop mysql
. 那么它们之间有什么区别呢?
经过调研,发现主要有如下区别:
net
is older – from the days of MS-DOS and OS/2, in fact.
sc
only appeared with Windows NTnet
can only start, stop and pause services.
sc
has more advanced controls, can query state, create and delete services, change their configuration and security:sc config mysql start= demand
net
only works locally.
sc
can be used over the network:sc \snow start rpcapd
net
accepts display names:net start "Windows Firewall"
sc
always requires a service name:sc start SharedAccess
二者最重要的区别在于 net
是一种同步的管理方式,sc
是一种异步的管理方式。怎样理解呢?
我们想重启mysql服务,可以直接用 net stop mysql & net start mysql
, 也就是说 命令会依次执行关闭和开启mysql的步骤,当服务确认关闭之后,才会接着执行开启的指令。
此时,如果我们用 sc stop mysql & sc start mysql
, 则会失败。因为 stop mysql
只是发送了一个关闭mysql的信号而已,此时服务尚未完成关闭,这时候执行 sc start mysql
,就会遇到错误。