Bill: Use Srvany.exe to run any program as a Windows service

Source: Internet
Author: User

What is Srvany.exe?

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.

How do I get it?

You can get it either by downloading and installing Microsoft Windows Resource kits or by 1 (domestic lines), 2 (foreign lines) that I share.

How do I use it?

After you get to Srvany and decide to start a program as a service, first install Srvany as a system service, with a number of installation methods, such as Microsoft Windows Resource Another handy gadget in the kits Instsrv.exe for installation (), copying Srvany.exe and Instsrv.exe to C:\Windows\System32\, We can install the Srvany.exe service through the following command line:

Instsrv ServiceName C:\Windows\System32\srvany.exe

ServiceName is the name of the service that you define, which can be the name of 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, configure the method, start – Run –regedit, open the registry, and navigate to the following path.

Hkey_local_machine\system\currentcontrolset\services\servicename

The same servicename is the name of the service you customized when you just installed the service.

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 instance, the service name we configured here is Nginx, the rest is Nginx installation configuration situation.

Of course, there is a relatively simple way, that is, save the following text as a *.reg file, and then double-click Import Registry.

123456
Windows Registry Editor Version 5.00 [hkey_local_machine\system\currentcontrolset\services\ service name \parameters] " Application "=" value is the address of the program that you want to run as a service "appdirectory" = "Value for the folder path of the program that you want to run as a service" "appparameters" = "value for the parameters you want to start as a program to run as a service"

July 14, 2011 update

Find Microsoft's official article, "How to create a user-defined service", and you can take a look.

February 27, 2012 update

Today, a friend asked that a form program through Srvany as a service run, the desktop bottom right icon and the form can not be displayed, this involves the operation of the service, the General Service program is not included in the form, so the system by default may suppress these services generated by the form, if your service program is more special , you do need to appear in the form, you can refer to the following methods:

Control Panel – Management tools – service (or start – Run –services.msc confirmation) Open Service Manager, select the service you just installed and need to show the form, then right-click the Select property, switch to the "Login" tab, tick "Allow service to interact with desktop" and press OK to save, restart your Service to see if the form appears:

July 3, 2012 update

In order to make use of Srvany.exe to create custom services I specifically wrote a service to create a management tool called Srvanyui, you can take this article "Srvanyui Service Management tool release" To get more information, here is a:

July 5, 2012 update

Find a Microsoft article to refer to the "Troubleshooting using Cmd.exe SrvAny".

July 23, 2012 update

Recently a friend consulting why tick "allow service and desktop interaction", the form program still can not display, in fact, this method only applies to Windows XP or Windows 2003 series operating system, for the above version of Windows Vista, Windows 2008, Windows 7 and Windows R2, Microsoft has made a change, using session 0 sessions isolation policy, so use this method to force the service form display will appear prompt box, only manually allow the interface, and the desktop style will be changed:

Programs that are running on this computer are trying to display a message, and your program may need your information or permissions to complete the task.

Interactive Service Detection
A program that is running on this computer is trying to display a message
The program may need your information or permissions to complete the task.

The prompt for Vista and high-version Windows interaction appears to be controlled by the interactive Services detection service. Disabling this service will not show the above prompt box, and the form will not appear.

More detailed information can be found in the MSDN Interactive Services article.

Pay special attention to the following paragraph:

Important Services cannot directly interact with a user as of Windows Vista. Therefore, the techniques mentioned in the sections titled Using an Interactive Service should is used in new code.

If you want to display the form on a new Vista and above operating system, we should use the new technology, such as using Wtssendmessage to display a dialog box in a user session, or separating the service program from the form and then using process communication (recommended).

The method of programming can refer to this article, "Resolving Vista and Win7 in Windows Services Interactive Desktop permissions issue: Penetrating Session 0 Isolation"

Unfortunately, the current approach is limited to programming, and other effective methods I haven't found yet.

Some reference documents:

    • "What's Interactive Services Detection and why are it blinking at Me?"
    • "How can a Windows service execute a GUI application?"

February 27, 2012 update

For command line with parameters to create a custom service directly from Srvany.exe, refer to the article "Wscript/vbscript command line parameters to create a custom service using Srvany.exe."

END

Transferred from: http://wangye.org/blog/archives/42/

Bill: Use Srvany.exe to run any program as a Windows service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.