How to register an EXE as a Windows service that runs directly from the background

Source: Internet
Author: User

Method One: Use the command sc that comes with Windows to create using the SC Create method. Example: sc create capturescreen binpath= F:\zwmei-project\decklink-learning\OutputBitmap\Debug\OutputBitmap.exe type= own start= Auto Displayname= screen_capture where Capturescreen is the service name that can be found in system services (by running Services.msc on the command line to open System services). BinPath is the path where your application resides. DisplayName The name of the service display, which can be found in the registry, by entering Regedit on the command line to open the registry, in HKEY_LOCAL_MACHINE--SYSTEM--CurrentControlSet To find your service display name) Note: In the SC command, there must be no space before the = sign, and a space after the = sign, remember. Also, open the command line as an administrator. This method does not necessarily succeed, and if your EXE does not conform to the specification of the service, it may fail to start. Here we discuss the second method
Method Two: In the case of failure of the first method, we can use Instsrv.exe and srvany.exe two small tools to worry about us we can download Instsrv.exe and Srvany.exe in our website and put it in our own folder, you can put the folder in the C drive. Below we begin to register the service. Run the command line as an administrator, first enter the folder where the tool is located, such as: C:\Tools. Execute C:\tools\instsrv.exe ServerName C:\tools\srvany.exe so we create a service named ServerName Srvany, so where is our own exe? Below we open the registry to find ServiceName this service (location under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services), then right-click on new item with name parameters. Click the item, and then create a new two string value on the right. The first name is application, and the value is: application path, such as: C:\myApp.exe. The second name is appdirectory and the value is: The directory where the application resides, such as C: \. Next we go into the system service, find servicename this service, double-click into its properties. Settings allow interaction with the desktop. Then start the service. At this point we have completed the process of registering the EXE as a service. Here we analyze: Instsrv.exe can create and delete services, however, if there is no srvany.exe participation, the created service may not start. So what did Srvany.exe do, after starting the service we can find our service in Task Manager, then right click on the service, select Go to process, (if no item in the process is selected, click Show All user processes below and then select Go to process), we see the srvany.exe, not our Own EXE. Originally our EXE became a child of it, started by Srvany.exe help.

How to register an EXE as a Windows service that runs directly from the background

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.