Contacts

How to run an application as a Windows service. From exe to service

How to run an application as a Windows service



Is it possible to run a client application as a service? In one of the articles, ways to create a service Windows standard OS means. However, not every console application will be able to start as a service, and programs with graphical interface In principle, they do not know how to work this way. But it is still possible to run the application as a service, and a program with an original name will help us with this Non-Sucking Service Manager.

NSSM is free and open source software and supports all Microsoft operating systems from Windows 2000 to Windows 8. NSSM does not require installation, just download and unzip it. The distribution includes versions for 32- and 64-bit operating systems. You can get the program from the website nssm.cc, at this moment The latest stable version is 2.21.1, which is what I will use.
To demonstrate the capabilities of NSSM, let’s try to run Windows Notepad as a service on Windows 8.1.

Creating a Service

To create a service named notepad launch the command console, go to the folder with the unpacked NSSM (for 64-bit Windows) and enter the command

Code:

Nssm install notepad

which opens the NSSM graphical installer window. To create a service, just specify the path to the executable file in the Path field and click the “Install service” button. Additionally, in the Options field you can specify the keys required to start the service.

You can also specify some additional parameters when creating a new service.

The Shutdown tab lists the shutdown methods and timeouts used when the application shuts down normally or crashes. When NSSM receives a stop command (for example, when an application is shut down), it attempts to stop the controlled application in a normal manner. If the application does not respond, then NSSM can forcefully terminate all processes and subprocesses of this application.

There are four steps to shutting down the application, and by default they will be used in this order:

In the first step, NSSM tries to generate and send a Ctrl+C event. This method works well for console applications or scripts, but is not applicable for graphical applications;
NSSM then detects all windows created by the application and sends them a WM_CLOSE message, causing the application to exit;
The third step is that NSSM calculates all threads created by the application and sends them a WM_QUIT message, which will be received if the application has a thread message queue;
As a last resort, NSSM can call the TerminateProcess() method, forcing the application to terminate.

It is possible to disable some or even all methods, but different methods work for different applications and it is recommended to leave everything as is to ensure the application shuts down correctly.

By default, when a service crashes, NSSM tries to restart it. On the “Exit actions” tab, you can change the automatic action when the application terminates abnormally, as well as set a delay before the application automatically restarts.

On the “Input/Output (I/O)” tab, you can set the redirection of application input/output to a specified file.

On the “Environment” tab, you can set new environment variables for the service, or override existing ones.

You can also not use graphical shell and immediately create a service in the console with the following command:

Code:

Nssm install notepad "C:\Windows\system32\notepad.exe"

Service management

After creating the service using NSSM, go to the Services snap-in and find the notepad service. As you can see, in appearance it is no different from other services; we can also start it, stop it, or change the launch mode. However, note that nssm.exe is listed as the executable file.

If we need to run an ordinary application as a Windows service, then we have at least two ways to do this. Firstly, there are the Srvany & Instsrv utilities from the Resouce Kit, and secondly, there is a very interesting application called Non-Sucking Service Manager, which is free open source software that can run in operating systems Microsoft systems, starting with Windows 2000 and ending with Windows 8. At the same time, NSSM does not require installation, and you can get it on the official website nssm.cc. Let's take a closer look at both methods of running an application as a Windows service.

Method one – Srvany & Instsrv.

First, you should make sure that you are working under account administrator, in this case you not only have enough rights for any actions, but also the service created under this account will continue to work under other accounts. Next, copy the files instsrv.exe and srvany.exe to the system32 folder. Run the following command from the command line:

instsrv MyService c:full_pathsrvany.exe (here MyService is the name of the newly created service you specified). Now, to configure the service, go to the “Control Panel”, then to the “Administration” section and then to the “Services” section, here we find our created service and double-click on it with the left mouse button.

In the properties window that appears, we note how our service will start: Automatic - it will start automatically when Windows boots, Manual - it will start only when you start it manually, Disabled - it will not start at all. If necessary to running service interacted with your desktop, then check the “Allow Service to Interact with Desktop” checkbox. Now we launch the registry editor in the branch:

HKLM SYSTEM CurrentControlSet Service Your_service_name

create a key called “Parameters” (without quotes) and set it to the value “Application” (without quotes) of type REG_SZ in which you specify the full path to the executable file that starts as a service. All that remains is to restart the computer or start the service manually.

Method two – Non-Sucking Service Manager.

Open a command prompt (with administrator rights, of course) and go to the folder where we previously unpacked NSSM. Here we enter the command

nssm install our_service

As a result of executing the command, the NSSM installer window will open. In order to create a service, we just need to specify the path to the executable file in the Path field and click the “Install service” button. In addition, in the Options field we can specify keys if they are necessary to start the service.

Now let's move on to setting up some additional parameters. The Shutdown tab lists shutdown methods that are used when a service shuts down normally or an application crashes. It is worth leaving all the boxes ticked, since different methods work for different applications.

Further, with the default settings, if the service crashes, NSSM tries to start it again, but on the “Exit actions” tab you can specify what action will be performed in the event of an abnormal shutdown of the application and set a delay before automatically restarting the application. On the “Environment” tab, we can set new environment variables for the service, or override existing ones.

In case we don’t want to use a graphical shell, we can immediately create a service from the command line with the command:

nssm install notepad ?full_path_to_executable_file_file.exe?

To remove a service, enter the command:

nssm remove our_service

and confirm its removal by entering the command:

nssm remove notepad confirm

then confirmation will not be requested.

These are fairly simple ways to start an application as a Windows service, now that your application starts automatically as a service.

(No ratings yet)

Your browser may suddenly show you services.exe process in task manager. It's definitely a bad idea to take it as a coincidence. no, it was a planned attack to get into your computer. Your computer may have recently been infected with risky malware. Unfortunately, you will have to deal with this problem right now. And it is in your best interest to find it as quickly as possible and eliminate the services.exe adware.

You can see the services.exe process in the task manager, a simple right click will show you C:\Windows Temp (RANDOM) infected folder location. However, this does not mean that the problem is solved and you can now delete this issue. Vice versa! You will not be able to remove threats manually because the source of persistent advertisements is hidden under many other services and processes running on your computer. The adware that you have on your system works with the self-defense skill. It itself is a mask and remains in the system for a long time.

Infiltration of the services.exe process may occur due to personal user actions or security issues. In the first case, certain users’ actions associated with thoughtless and stupid installation can cause the appearance of malware. They must be vigilant and attentive at all times they are online, and especially careful with loading. In the second case, people rely on antivirus software and do not know that sometimes it may not support tracking all threats and preventing their installation. It's always good idea for switching for reliable software, which can carry out its main functions.

Removing the services.exe process is possible with just a few clicks. The guide below can help you with the basic steps you need to do with our GridinSoft Anti-Malware tool. Automatic removal leaves no chance for all variants of malware. Follow the tutorials below to reset the infected browser, which is mandatory.

Download a reliable services.exe removal tool:

Detailed instructions on how to remove services.exe infection.


Preventative tips for your PC from being infected with services.exe again in the future:

GridinSoft Anti-Malware offers an excellent solution that can help prevent your system from being contaminated by malware ahead of time. This feature is called “About the Protection Perspective”. By default, it is disabled after installing the software. To enable it, please click on “ Protect” and click on the “ button Start

This useful feature may allow people to prevent malicious software from being installed. This means when you try to install some suspicious files In the future, Protection will block this installation attempt ahead of time. THE NOTE! If users want dangerous programs to be installed, they can select the "Ignore Always" button. In case you want to stop malware, You must select "Block always".

In this article we will get acquainted with in a simple way allowing remove any service in Windows 7 by means of itself operating system without using third party programs.

Before you begin, there are a few things you need to understand:

  • When you delete a service, it forever will disappear from the system, and restoring it is not easy, and in some cases it is simply impossible
  • Removing certain services may cause certain programs to not work. Therefore, you should not delete a service if you are not 100% sure what it is responsible for.
  • Do not remove Windows 7 system services, because... this may cause the entire system to fail

We will also try to understand in what cases there is a need to remove a Windows service.

  • Often, when programs are removed from the system, they leave their services intact, and every time the computer boots, the system tries to start such a service, but due to the lack of executable or library files, it cannot do this, generating an error.
  • Some viruses and Trojans can create a new service in the system to disguise their destructive actions. And even if your antivirus removes the virus body, the service may remain and will have to be removed manually.
  • It is also possible that system performance is reduced due to the presence of large quantity processes running as services, and you decide to remove (rather than just stop) a number of services in Windows 7 that are no longer needed.

To remove a service in Windows 7, you need to know its name. To do this, open the service management window Start -> Settings -> Control Panel-> Systems and Maintenance->Administrative Tools->Services.
In the services window that appears, find the service that you plan to remove (in my example it is “ Adobe Lm Service”)

Double-click on the selected service and in the properties window that appears, its name will be displayed in the “Service name” field (my service name is Adobe LM Service, i.e. it matches the name in the list of services, but usually this is not the case), copy it to the clipboard.

Then stop the service by clicking the "Stop" button

Removing a service in Windows from the command line

Open a command prompt window (cmd.exe) with administrator rights (“Run as administrator”). To remove a service in Windows 7, you can use the system command sc. The sc.exe command is a command line utility that is used in Windows 7/Vista/XP to create, edit, and delete services. According to the TechNet documentation, sc.exe:

sc. exe (Service Controller) interacts with installed services, receiving and setting their parameters. utilityS.C.. exe can be used to test and debug programs running as services. Service properties are stored in the registry, command parametersS.C.. exeallow you to modify the values ​​of these properties, as well as control the starting and stopping of services. PossibilitiesS.C.. exe are in many ways similar tommcconsoleServiceslocated in the Control Panel.

The syntax for the service removal command is:

Sc delete ServiceName

If the service name contains spaces (as in our case), it must be enclosed in quotes:

Sc delete “Adobe LM Service”

If the sc delete command is successful, command line a message should appear DeleteService SUCCESS

Now, if you press F5 in the service management console, you will see that the service has been deleted and does not appear in the list.

Removing a service using the Registry Editor

An alternative method for removing services in Windows 7 involves using Registry Editor.

Open the registry editor (regedit.exe), and go to the branch HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services. It contains a list of all services installed on the system.

Find the registry hive name that matches the name of the service you want to remove.

Make sure that the values DisplayName and ImagePath contains, respectively, the name and path to the executable file of the service that you plan to remove.

Right-click on the name of the found registry branch with the service name and select “Delete”. After which the service will be removed from the system.

Have you ever wanted to run an application as a system service? I think so, given that some programs have this feature built in by default. Did you know that an application running as a service runs much faster and takes up less memory space?


In this article we will look at a small utility Any Service, which in two clicks will help you launch any application as a system service. Any Service is a wrapper around two standard utilities srvinstw And instsrv included with Windows 2000 Server and for its normal operation you will need Administrator rights.

The program is completely free, takes up only 49 KB and does not require installation. The interface is intuitive and provided with detailed explanations in the form of tooltips.

The main window of the program allows you to primary settings your future service:

In the first field, enter the full path to the executive file of the application that will be launched as a service. In the “Service Name” column we indicate what our service will be called. In "Service Description" - any description of the new service that you understand.

Interaction with the desktop - check if the application has an icon in the system tray;

Autostart service - check if you want the service to start automatically;


Start immediately after creation - check this box if you want the service to start immediately after its creation; As an example of how the utility works, let's try to run the popular file manager Total Commander.

After filling in all the required fields, click the “Create” button.

That's it, the new service has been created and is ready to work. You can look at the result of your actions by using the “Services” button, which opens a group snap-in.

As you can see, our new Total Commander service is live. Now you can change its settings just like any other system service.

If you want to remove a service, use the "Delete..." button in the main program window. The following window will open in front of you:

We find the required service and click "Delete". The Total Commander service no longer exists.

Known problems: before the first start, it is advisable to disable antivirus program otherwise further work program will not be possible, because when first launched, it looks for both utilities (srvinstw and instsrv) in the %WINDIR%\System32\ folder and if it does not find it, it copies them from its own resource.

Another 1 way:

1. It is best to do this under an admin account, then the created service will continue to work with any other account.

2. Copy files instsrv.exe And srvany.exe to some system directory, for example, in winnt\system32\ (Taken from Resouce Kit \compmgmt.cab\srvany.exe, instsrv.exe. There is also srvinstw - this is a GUI step-by-step shell that does the same as instsrv, but also can install/uninstall services remotely).

3. Run from the command line: instsrv MyService c:\full_path\srvany.exe where MyService is the name of the newly created service you created. If there are spaces in the name, then the service name must be enclosed in quotes.

4. Now you need to configure this service. Go to: Start -> Settings -> Control Panel -> Services, find your newly created service and click on it 2 times with the left mouse button. In the window that opens, indicate how your service will start: Automatic - will start automatically when the computer boots, Manual - will start only when you start it manually, Disabled - will not start at all. If you want to see the running service as a window on the desktop, then check the "Allow Service to Interact with Desktop" checkbox.

5. Run regedt32 and create the key "Parameters" (without quotes) in: HKLM\SYSTEM\CurrentControlSet\Service\Your_service_name\

6. Create under the “Parameters” key you created (without quotes) value “Application" (без кавычек) тип -- REG_SZ: и пpописываете там полный пyть к исполняемомy файлy. !}

For example, Application: REG_SZ: c:\full_path\t-mail.cmd

7. Reboot your computer or start the service manually.

It is better to exit such services using the flag.

Did you like the article? Share it