China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-07 03:11
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to use batch processing to start and stop services View 2,095 Replies 22
Floor 16 Posted 2007-01-24 06:42 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by jasonwang at 2007-1-23 14:22:
@echo off
for /f "delims=" %%i in ('SC QUERY TLNTSVR^|FIND "STATE"') do ( I understand this, do the work after DO according to STATE)
echo %%i|find /i "RUNNING" ...


  Go to the 4th floor of this post to have a look.
Floor 17 Posted 2007-01-24 10:50 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 2
Posts 1
Joined 2007-01-13 12:31
19-year member
UID 76401
Gender Male
Status Offline
Floor 18 Posted 2007-01-24 12:07 ·  中国 广东 广州 天河区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
RE: jasonwang

&& means that if the command is executed successfully, the command following it will be executed
|| is exactly the opposite of &&, meaning that if the command fails to execute, the command following it will be executed
我很菜,但我很努力~
Floor 19 Posted 2007-01-24 23:15 ·  中国 北京 朝阳区 联通
初级用户
★★
Credits 122
Posts 54
Joined 2006-11-03 04:24
19-year member
UID 69380
Gender Male
Status Offline
Thanks to the explanation of the upstairs, I didn't succeed in the test under 03. Is this command invalid when the service is in the disabled state?
Floor 20 Posted 2007-01-24 23:40 ·  中国 北京 朝阳区 联通
初级用户
★★
Credits 122
Posts 54
Joined 2006-11-03 04:24
19-year member
UID 69380
Gender Male
Status Offline
C:\>sc query tlntsvr

SERVICE_NAME: tlntsvr
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0

C:\>services.bat
Press any key to continue . . .

C:\>sc query tlntsvr

SERVICE_NAME: tlntsvr
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0

C:\>

@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)
)
pause
Floor 21 Posted 2007-01-25 00:09 ·  中国 湖南 衡阳 电信
中级用户
★★
Credits 322
Posts 144
Joined 2007-01-10 13:00
19-year member
UID 76062
Gender Male
Status Offline
It's okay with the net start command. SC is not available under WIN2000.
Floor 22 Posted 2007-01-25 00:41 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by jasonwang at 2007-1-24 10:40:
C:\>sc query tlntsvr

SERVICE_NAME: tlntsvr
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ...

There is an error in your code. Try copying the code I wrote.
Floor 23 Posted 2007-01-25 02:47 ·  中国 北京 朝阳区 联通
初级用户
★★
Credits 122
Posts 54
Joined 2006-11-03 04:24
19-year member
UID 69380
Gender Male
Status Offline
Got it, add /i after the first find. There should be a space before start= auto. Hehe, thank you everyone
Forum Jump: