Srvany.exe Introduction
Srvany.exe is a useful gadget for the Microsoft Windows Resource Kits toolset to run any EXE program as a Windows service. That is to say, Srvany is only the service shell of its registered program, this feature is very useful for us, we can let our program start with the system account, or implement the random start and start, can also hide unnecessary windows, such as the console window and so on.
Resources Download
You can get it by downloading and installing Microsoft Windows Resource Kits or download it directly in this article.
The console program in the example is simply a constant write time to the current path.
Srvany Package test program, test program (incl. console project)
How to use
When you get to Srvany and decide to start a program as a service, please first install Srvany as a system service, the specific installation method is many, here use INSTSRV, the syntax is as follows:
Installing INSTSRV ServiceName C:windowssystem32srvany.exe
Uninstalling Instsrv ServiceName Remove
(ServiceName is the name of the service you define yourself, which can be the application that you want to start as a system service.) )
After the installation, we need to configure the Srvany.exe so that we can load the program we specified, and configure the method, start-run-regedit, open the registry, and navigate to the following path. Hkey_local_machinesystemcurrentcontrolset Servicesservicename
If the service name does not have a parameters project, right-click the new item on the service names project, name parameters, and then navigate to the parameters item to create a new string value for the following.
The name application value is the address of the program that you want to run as a service.
The name Appdirectory value is the folder path of the program that you want to run as a service.
The name appparameters value is the parameter you need to start the program that you want to run as a service.
For example, here is a configuration example, the service name we configured here is MyService, the following is the installation configuration of MyService:
At this point, MyService is already installed as a Windows service and can be viewed in the Window service item.
This article, of course, is not just a copy of the article, recently in the study batch, the operation of which uses batch processing to complete.
Batch processing instructions
1. Run-install.bat encapsulates the operation of the installation service (mentioned above). Need to pass in parameters with service name, program name.
Copy CodeThe code is as follows:
@echo off
The REM parameter, in turn, is the service name executable file name
@echo Service Name:%1
@echo Program Name:%2</p> <p>rem define the program path that needs to run
Set curexe=%~dp0%2
REM Definition Registry path
Set Regpath=hkey_local_machinesystemcurrentcontrolsetservicesmyserviceparameters
REM Definition Srvany.exe file path
Set sourcepath=%~dp0srvany.exe</p> <p>rem into the current directory
cd/d "%~dp0"
REM Installation Boot Service
Instsrv%1 "%sourcepath%"
@echo Service Add complete </p> <p>rem Add Registry Syntax: REG ADD Registry path/V Key name/T value type/d data/F indicates forced modification without prompting </p> <p>rem name Appl The Ication value for the program address that you want to run as a service/d corresponds to a parameter with a slash not to escape quotes, but a path with a slash, the default is to escape the quotation marks, and the extra slash is to preserve the quotation marks
REG ADD%regpath%/V appdirectory/t reg_sz/d "%~dp0"/f</p> <p>rem name appdirectory value for the folder path of the program that you want to run as a service
REG ADD%regpath%/V application/t reg_sz/d "%curexe%"/F </p> <p>rem name appparameters value The parameters you need to start the program you want to run as a service
REG ADD%regpath%/V appparameters/t reg_sz/f
@echo Registry Add complete
2.install.bat command meaning: Enter the current directory, call the current directory of the Run-install.bat file, and pass in parameters, complete the service installation. Service Name: MyService Execution Program: Console.exe
Copy CodeThe code is as follows:
@echo off
CD/D%~dp0
Call Run-install.bat MyService Console.exe
Pause
3.run-del.bat simply encapsulates the operation of the uninstall service, which can be passed into the service name.
Copy CodeThe code is as follows:
@echo off
The REM parameter is the service name in turn
@echo Service name:%1</p> <p>rem into the current directory
CD/D%~dp0
REM Offload Boot service
Instsrv%1 Remove
4.del.bat command meaning: Enter the current directory, call the current directory of the Run-del.bat file, and pass in parameters, complete the service uninstall. Service Name: MyService
Copy CodeThe code is as follows:
@echo off
CD/D%~dp0
Call Run-del.bat MyService
Pause
Summarize
1. It is easy to add the program to the system service by following the above actions.
2. Using the scenario, the program requires a boot-up and is not logged in the window. (The normal boot-up application needs to enter the machine user name, password to enter the desktop before starting)
3. After the program is deployed as a service, the program can still double-click Start, if not required, it is recommended to add a command line parameter in the program to prevent double-click Start the program.
4. In the properties of the service, you can set it to interact with the desktop, at which point the window prompts for an interactive message and then displays the program form when clicked.
5. If your program is made into an installation package, invoking batch processing of the installation service and invoking the batch of the offload service, it can be placed on the installer and uninstall the program to perform, simplifying the user operation.