我知道用sc start/stop 服务名 来开关服务,但是我现在想先判断服务是打开的还是关闭的,要是打开的就关闭服务,要是服务是关闭状态就打开服务,这个怎么来实现?是不是用到query这个参数啊,我刚学批处理,高手们指点一下。
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off
for /f "delims=" %%i in ('SC QUERY TLNTSVR^|FIND "STATE"') do (
echo %%i|find /i "RUNNING" && (
sc stop tlntsvr
sc config tlntsvr start= disabled)||(
sc config tlntsvr start= auto
sc start tlntsvr)
)
exit/b
@echo off
for /f "delims=" %%i in ('SC QUERY TLNTSVR^|FIND "STATE"') do (
echo %%i|find /i "RUNNING" && (
sc stop tlntsvr
sc config tlntsvr start= disabled)||(
sc config tlntsvr start= auto
sc start tlntsvr)
)
exit/b
Originally posted by rcbblgy at 2007-1-23 23:50:
非常感谢,这个服务是虚拟机的服务。我平时把它设成手动,用虚拟机的时候再开服务,所以服务启动类型就不设了,全当知识学了吧,呵呵。
不过 ...