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-13 19:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Tutorial] [Update] Treat any executable file (including batch files) as a service DigestI View 64,565 Replies 262
Original Poster Posted 2006-06-22 14:18 ·  中国 上海 杨浦区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
■Note■ Someone actually added me on MSN to ask the difference between this tool and the SC command under XP. It's really frustrating.

Here's the clarification: First, a Windows service is not an ordinary executable program. For an application to become a service, it must call the standard Windows Service API according to the contract and interact correctly with the Windows Service Manager. For details, refer to:
http://msdn.microsoft.com/en-us/library/ms681921(VS.85).aspx and
http://msdn.microsoft.com/en-us/library/ms685967(VS.85).aspx. The detailed API reference is at: http://msdn.microsoft.com/en-us/library/ms685942(VS.85).aspx.

That is, the function of the SC command is to install, delete, start, and stop a service. While the function of runassrv is to turn any non-service program into a service.

If this is still not clear, try using SC to add a certain batch file or notepad.exe as a service and see what happens.


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
New content in version 1.1.0.628:

■ All Actions (such as: add / remove, etc.) do not need to add a prefix anymore.
■ New pause / continue operations.
■ From now on, a runassrv service can concurrently run multiple applications specified by /cmdline.
■ runassrv.exe itself does not need to be placed in the system search path.
■ New control operation to send a control code to the specified service.
■ New listsrv operation to list all services and drivers, supporting many filtering conditions.
■ New -logfile and -loglevel options, with log recording function.
■ New -unstoppable option, the system service manager will refuse to stop a service installed with this option.
■ Memory contraction strategy, typically with memory overhead less than 300KB.
■ Solved the problem that the start / stop command is invalid on some systems.

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
A small thing written a few years ago, for everyone's amusement~

Run As Service

A tool to run any executable file (including batch files and scripts) as a system service

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Introduction:

■ Run any executable file as a system service.
■ Originally mainly for porting some Linux daemons; can also be used to start any application and maintenance scripts.
■ Runs quietly, unless the Interactive mode is specified, no windows will pop up.
■ No need to log in, it runs automatically after the system starts, without waiting for the user to log in.
■ As a side function, it supports starting, stopping, and deleting any system service.
■ Completely take over the instructions of the system service manager (start, stop, etc.). After the running program terminates, it automatically submits the status to the service manager and exits by itself, without resident memory.

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Help screen:


C:\Documents and Settings\Administrator>
#runassrv

===========================================================================
Run As Service Ver 1.1.0.625 by BaiYang / 2004 - 2006, Freeware
===========================================================================
Run any program as a Service

USAGE: runassrv <Action> <Options>
===========================================================================
Actions:
add - Add a Service.
remove - Remove a Service.
start - Start a Service.
stop - Stop a Service.
pause - Pause a Service.
continue - Continue a paused Service.
control - Control a service by send it a op-code
listsrv - List all installed services on local system
listgrp - List all service load order groups on local system (by start
order).
-h - this screen
===========================================================================
Options:
-cmdline - when the service start, witch program you want to run.
-name - the service name.
-dispname - service's display name in service manager
-desc - service's description in service manager
DEFAULT: none
-type - service type, can be:
FileSystemDriver
KernelDriver
OwnProcess (DEFAULT)
ShareProcess
InteractiveProcess
NOTE: set this option incorrectly may endanger your system!
-starttype - service start type, can be:
SystemStart
BootStart
AutoStart (DEFAULT)
DemandStart
Disabled
NOTE: set this option incorrectly may endanger your system!
-errctl - service error control policy, can be:
ErrorIgnore
ErrorNormal (DEFAULT)
ErrorSevere
ErrorCritical
NOTE: set this option incorrectly may endanger your system!
-group - specify service load order group
DEFAULT: none
-depen - names of services or load ordering groups that the system
must start before this service, delimited by '/'
DEFAULT: none
-user - specifies the name of the account under which the service
should run.
DEFAULT: LocalSystem
-pass - contains the password to the account name
DEFAULT: none
-priority - priority of the program you want to run, can be:
Idle
BelowNormal
Normal (DEFAULT)
AboveNormal
High
RealTime
-unstoppable - make service unstoppable by system service control manager.
-opcode - for "control", specify the operation code.
-logfile - specify the logging target.
DEFAULT: don't log to file.
-loglevel - specify the lowest logging level, can be:
DebugOnly (Most Detail)
Info
Warning
Error (DEFAULT)
FatalError
Disabled (Close Logging Output)
===========================================================================
Special Options With "listsrv":
-name - list service name that match the wildcard pattern
DEFAULT: *
-dispname - service display name's wildcard pattern.
DEFAULT: *
-pid - service belong to specified process.
DEFAULT: any
-type - specify service types to be match, delimite by "/".
DEFAULT: any
-starttype - specify service starttypes to be match, delimite by "/".
DEFAULT: any
-group - service belong to the load order group
DEFAULT: any
-state - service's current state, can be:
active
inactive
DEFAULT: any
===========================================================================
Examples:
runassrv add /cmdline:"c:\tools\myapp.exe -arg1 -arg2" /name:"mysrv"
runassrv add /cmdline:myapp.exe /cmdline:yourapp.exe /name:mysrv
runassrv add /cmdline:notepad /cmdline:vi.bat /type:interactiveprocess /priority:AboveNormal /name:testsrv /logfile:C:\test.log /loglevel:debugonly /dispname:"My Test Service" /desc:"This is a Test Service"

runassrv start /name:wuauserv
runassrv stop /name:wuauserv
runassrv pause /name:iisadmin
runassrv control /name:wuauserv /opcode:1

runassrv listsrv /name:w*
runassrv listsrv /type:KernelDriver/FileSystemDriver
runassrv listsrv /starttype:SystemStart/BootStart
runassrv listsrv /group:pnp_tdi
runassrv listsrv /pid:1234
runassrv listgrp


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Simple Chinese help:


C:\Documents and Settings\Administrator>
#runassrv

===========================================================================
Run As Service Ver 1.1.0.628 by BaiYang / 2004 - 2006, Freeware
===========================================================================
Run any executable program as a system service

Usage: runassrv <action> <options>
===========================================================================
Actions:
add - Add a service.
remove - Remove a service.
start - Start a service.
stop - Stop a service.
pause - Pause a service
continue - Continue a paused service.
control - Send a control code to the specified service.
listsrv - List all services and drivers that meet the conditions on the current system.
listgrp - List the priority order of all service startup groups on the current system.
-h - This help screen.
===========================================================================
Options:
-cmdline - When the service starts, specify which program you really want to run. This option can be used multiple times, each specifying an application to run. When the service starts, these applications will be executed concurrently.
-name - Specify the system service name (used for system operations such as net start, etc.).
-dispname - Specify the service display name that the user will see (the name seen in the service manager).
-desc - Specify the service description (the service description information seen in the service manager)
Default: None
-type - Specify the service type, which can be the following types:
FileSystemDriver : File system and driver, will be loaded before the kernel is loaded. Note that services at this level can hardly use any system APIs.
KernelDriver : Kernel-level driver, loaded immediately after the kernel is loaded. Services at this level can only use restricted APIs.
OwnProcess : Separate process service, standard service, started after the Win32 subsystem is ready, default.
ShareProcess : Shared process service, that is, several services share the same process. Many services relying on svchost use this type.
InteractiveProcess: Interactive service, the service can interact with the user. Except for this type, all other types of services cannot have a user-visible interface.
Note: Incorrectly setting this option may make the system unstable or even unable to start! If you don't know what you are doing, please don't try the first two items.
-starttype - Service startup type, including:
SystemStart : System-level startup, started after the kernel is initialized.
BootStart : Started by the system loader (before the kernel is initialized).
AutoStart : Start automatically, started after the Win32 subsystem is initialized, default.
DemandStart : Manual.
Disabled : Disabled.
Note: Incorrectly setting this option may make the system unstable or even unable to start! If you don't know what you are doing, please don't try the first two items.
-errctl - Specify the error handling strategy when the service has an error, which can be:
ErrorIgnore : Ignore the error, do not rescue the service, the system continues to run
ErrorNormal : Record to the system log and pop up a dialog box to prompt the user, default. (Default)
ErrorSevere : Record the log and pop up a prompt box. If the current system has run in the last correct startup configuration, ignore the error, otherwise automatically restart to the last correct configuration.
ErrorCritical : The same as above, but if restarting to the last correct configuration still fails to start this service, it will blue screen.
Note: Incorrectly setting this option may make the system unstable or even unable to start! If you don't know what you are doing, please don't try the last two items.
-group - Specify the startup priority group that the service belongs to. The priority group can be listed in order by listgrp.
Default: None
-depen - Specify the services that this service depends on. The services specified here must be started correctly before this service starts. Multiple services are separated by "/". Here, the system service name must be specified, not the name seen by the user.
Default: None
-user - Specify the user identity, that is, the user account that this service uses to run
Default: LocalSystem (local system, highest authority), interactive services must use this account.
-pass - Specify the user password
Default: None (LocalSystem)
-priority - The running priority of the program specified by the cmdline parameter, which can be (no need to explain this):
Idle
BelowNormal
Normal (Default)
AboveNormal
High
RealTime
-unstoppable - The system service manager will refuse to stop the service installed with this option.
-opcode - Specify the control code to be sent for the control command. The control code "1" is actually equivalent to the stop command, used to stop the service. Except for a few standard control codes, most control codes correspond to behaviors defined by the service itself.
-logfile - Specify the log file
Default: Do not record the log file
-loglevel - Specify the detail level of log recording, which can be:
DebugOnly (record all running details)
Info
Warning
Error (Default)
FatalError
Disabled (Close the log output to the console and file)
===========================================================================
Special options when using the listsrv command:
-name - Specify the wildcard of the service name to be listed
Default: *
-dispname - Specify the wildcard of the service display name to be listed
Default: *
-pid - Only list services running in the specified process
Default: All processes
-type - Only list services of the specified type, multiple service types are separated by "/"
Default: All types
-starttype - Only list services of the specified startup type, multiple types are separated by "/"
Default: All types
-group - Only list services in the specified startup group
Default: Any group
-state - Only list services whose current state meets the specified value, which can be:
active : The service is currently in an active state (starting, running, etc.)
inactive : The service is currently in an inactive state (stopped)
Default : Any
===========================================================================
Examples:
runassrv add /cmdline:"c:\tools\myapp.exe -arg1 -arg2" /name:"mysrv"
runassrv add /cmdline:myapp.exe /cmdline:yourapp.exe /name:mysrv
runassrv add /cmdline:notepad /cmdline:vi.bat /type:interactiveprocess /priority:AboveNormal /name:testsrv /logfile:C:\test.log /loglevel:debugonly /dispname:"My Test Service" /desc:"This is a Test Service"

runassrv start /name:wuauserv
runassrv stop /name:wuauserv
runassrv pause /name:iisadmin
runassrv control /name:wuauserv /opcode:1

runassrv listsrv /name:w*
runassrv listsrv /type:KernelDriver/FileSystemDriver
runassrv listsrv /starttype:SystemStart/BootStart
runassrv listsrv /group:pnp_tdi
runassrv listsrv /pid:1234
runassrv listgrp

===========================================================================
About the separator of commands and parameters:
All parameters are prefixed with "-" or "/"; parameters that need to be assigned use ":" or "=" as the assignment operator, for example: -name="mysrv"; /name:"mysrv"; -name:"mysrv", etc. combinations are all legal.


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Copyright: Free software; the author is not responsible for anything. You can use it for any purpose, as long as you don't do bad things

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Contact the author: http://www.cn-dos.net/forum or asbai@msn.com

Try to contact via the forum or email for things. But if you like playing StarCraft and are a noob with the same hand speed as me (no more than 100), welcome to add my MSN ^_^

[ Last edited by asbai on 2008-6-3 at 01:33 PM ]
Recent Ratings for This Post ( 10 in total) Click for details
RaterScoreTime
qzwqzw +15 2007-03-15 08:40
JohnsonHE +1 2007-04-29 23:33
tashaxin +2 2007-05-22 21:16
chainliq +3 2007-06-01 04:37
xiaoshuq +2 2007-10-13 11:41
523066680 +15 2009-01-23 14:59
+1 2010-10-12 17:39
sky96111 +1 2016-01-08 23:02
zzkwhl +1 2017-08-13 07:43
zzz19760225 +2 2018-04-04 11:49
Attachments
runassrv.rar (115.34 KiB, Credits to download 1 pts, Downloads: 2847)
Floor 2 Posted 2006-06-22 23:44 ·  中国 广东 深圳 联通
初级用户
Credits 31
Posts 9
Joined 2006-06-21 14:24
20-year member
UID 57357
Gender Male
From cs
Status Offline
What a remarkable person!
Received it first.
Thanks
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
+1 2009-06-04 06:07
Floor 3 Posted 2006-06-23 00:22 ·  中国 辽宁 大连 联通
新手上路
Credits 9
Posts 7
Joined 2006-06-22 23:07
20-year member
UID 57425
Status Offline
Saw a post on DRL but didn't have permission to download, so I came here~ By the way, I want to ask the楼主 whether the process of this program will be terminated in the Task Manager? That is, register it as an unstoppable service.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
zzkwhl +1 2017-08-13 07:44
Floor 4 Posted 2006-06-23 01:52 ·  中国 上海 杨浦区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
Originally posted by Cappuccin0 at 2006-6-23 00:22:
Saw a post on DRL but didn't have permission to download, so I came here~~
By the way, I want to ask the LZ whether this program's process will be terminated in the Task Manager? That is, registered as that unstoppable ...


Hehe, what the hell is DRL? When making it, it was written as unpauseble, but not unstoppable. There's no such option either, because I really can't think of what use this option has.
Floor 5 Posted 2006-06-23 02:30 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
I tried it and found that asbai's programming level is really good. However, I found that both /add and /remove can be used, while /start and /stop sometimes can't be used normally (such as using net start and net stop can). For example:

C:\>runassrv /stop /name:"MySQL"

=======================================================================
Run As Service Ver 1.0.0.3 by BaiYang / 2004, Freeware
=======================================================================

[APPLICATION ERROR] 9 :: CSrvApp::_StopSrv() - unable stop the service.
service name = MySQL
error number = 0
error description = The operation completed successfully.

C:\>net stop MySQL
The MySQL service is stopping..
The MySQL service was stopped successfully.


C:\>
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 6 Posted 2006-06-23 09:48 ·  中国 上海 静安区 电信
初级用户
Credits 130
Posts 12
Joined 2003-10-22 00:00
22-year member
UID 11723
Gender Male
Status Offline
Learned and saved, thank you!
Floor 7 Posted 2006-06-23 15:31 ·  中国 上海 虹口区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
Originally posted by Wengier at 2006-6-23 02:30:
Tried it and found that asbai's programming level is indeed quite good. However, found that both /add and /remove can be used, while /start and /stop sometimes cannot be used normally (such as using net start and net stop then can be used). For example..


Can you trouble Brother Wengier to give a step to reproduce the fault? Actually, the original text has some special symbols like "" which may not be properly displayed, but the translation for the rest is as above. And the last sentence "能不能麻烦Wengier兄给个故障重现的步骤?;" is translated to "Can you trouble Brother Wengier to give a step to reproduce the fault? "
Floor 8 Posted 2006-06-23 15:47 ·  IANA 局域网IP(Private-Use)
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 9 Posted 2006-06-23 23:09 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Originally posted by asbai at 2006-6-23 03:31 PM:


Could you please ask Brother Wengier to give a step-by-step procedure to reproduce the fault? ;)


The reproduction method is actually in floor 5. Of course, "MySQL" can be changed to other similar existing services.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 10 Posted 2006-06-24 05:53 ·  中国 上海 虹口区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
Originally posted by Wengier at 2006-6-23 23:09:

There is actually a method to reproduce in floor 5. Of course, the "MySQL" there can be changed to other similar existing services.


sorry, I thought that what you said: "It seems that sometimes it can't be used normally" refers to that it occurs under certain specific environments and according to specific procedures.

I'll go and have a look now.
Floor 11 Posted 2006-06-24 12:52 ·  中国 上海 虹口区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
Which version of Windows are you using, Brother Wengier?
Floor 12 Posted 2006-06-24 14:05 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Windows XP SP2 English version
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 13 Posted 2006-06-25 13:26 ·  中国 广东 珠海 香洲区 电信
新手上路
Credits 2
Posts 1
Joined 2006-06-25 13:07
20-year member
UID 57538
Gender Male
Status Offline
Been looking for it for a long time!!!
Floor 14 Posted 2006-06-25 15:11 ·  中国 四川 成都 联通
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 15 Posted 2006-06-28 02:03 ·  中国 上海 虹口区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
Originally posted by electronixtar at 2006-6-25 15:11:
hoho~~~ Saw the original post

http://www.et8.net/bbs/showthread.php?t=763159


Brother electronixtar made a mistake? Take a closer look, this is the original post, ^_^
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
+1 2009-02-10 11:45
chenwenwei +1 2010-09-09 21:26
+1 2010-10-12 17:37
1 2 3 18 Next ›
Forum Jump: