The
Srvany.exe describes
Srvany.exe as a useful gadget for the Microsoft Windows Resource Kits toolset. Used to run any EXE program as a Windows service. That is, Srvany is only the service shell of its registration program, this feature is very useful for us, we can use it to enable our program to start with the system account, or to implement the random launch of the start, you can hide unnecessary windows, such as the console window and so on.
Resource Download
You can either download and install Microsoft Windows Resource kits or download it directly from this article. The console program in the
example is just a write time that is not constant to the current path.
Srvany Package download address test program, test program (including console project)
How to use
when you get to Srvany and decide to start a program as a service, Please install the Srvany as a system service, there are many specific installation methods, here use INSTSRV syntax as follows:
Install instsrv ServiceName c:windowssystem32srvany.exe
Uninstall Instsrv ServiceName Remove
(ServiceName is your own defined service name, which can be the name of the application that you want to start as a system service.
After the installation is complete, we need to configure the Srvany.exe so that we can load the program that we specify, and the way to configure it is to start-run-regedit, open the registry, and navigate to the path below. Hkey_local_machinesystemcurrentcontrolset Servicesservicename
If there is no parameters project under the service name, right-click the new item, Name is parameters, and then navigate to the parameters item, creating the following String values. The
Name application value is the address of the program 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.
Name AThe ppparameters value is the parameter you need to start the program that you want to run as a service.
For example, here is a configuration instance, the service name we configure here is MyService, and the following is the installation configuration of MyService:
at this point, MyService is already installed as a Windows service and can be viewed in window service items.
This article, of course, is not just a copy of the article, the recent learning batch, the operation of which use batch processing to complete.
Batch processing instructions
1. Run-install.bat encapsulates the operation of the installation service (mentioned above). An incoming parameter is required with a service name and a program name.
Copy Code code 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 be run
Set curexe=%~dp0%2
REM Definition Registry path
Set Regpath=hkey_local_machinesystemcurrentcontrolsetservicesmyserviceparameters
REM defines 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 completion </p> <p>rem Add Registry Syntax: REG ADD Registry path/V entry name/T value type//data F = Force Modify not prompt </p> <p>rem name Call application value for the program address/d that you want to run as a service the argument has a slash not to escape the quotation marks, but to the path and the slash, which is escaped by default, and the extra slashes are added to keep the quotation marks
REG ADD%regpath%/V appdirectory/t reg_sz/d "%~dp0"/f</p> <p>rem name appdirectory value is the folder path for the program you want to run as a service
reg ADD%regpath%/V application/t reg_sz/d "%curexe%"/F </p> <p>rem name Appparameters value to start the program you want to run as a service The Required Parameters
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 the parameters to complete the service installation. Service Name: MyService Execution procedure: Console.exe
Copy Code code as follows:
@echo off
cd/d%~dp0
call Run-install.bat myservice Console.exe
Pause
3.run-del.bat simply encapsulates the uninstall service operation, and the incoming service name is available.
Copy Code code as follows:
@echo off
REM parameter is the service name in turn
@echo Service name:%1</p> <p>rem into the current directory
cd/d%~dp0
rem Uninstall 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 the parameters, complete the service uninstall. Service Name: MyService
Copy Code code as follows:
@echo off
cd/d%~dp0
Call Run-del.bat MyService
Pause
Summarize
1. The above operation can easily add the program to the system services.
2. Using the scenario, the program needs to boot up and is not logged in window. (The regular boot-up application needs to enter the machine username, password to enter the desktop before starting)
3. After the program is deployed as a service, the program can still double-click to start, if you do not need to, it is recommended to add a command line parameter in the program to prevent double-click to start the program.
4. In the properties of the service, you can set it to interact with the desktop, at which point Windows prompts you for an interactive message, and the program form is displayed when you click.
5. If your program is made into an installation package, calling the batch of installation services and invoking the Uninstall service batch, you can place the installer and uninstall program to perform, simplifying user actions.