Creating service, enable and auto start them is a lot easier in Linux, however, what about Windows 10 or earlier systems such as Windows 7? Here we will discuss the steps to easily use any .exe (executable) or .bat file as WIndows systems service and mark them to start automatically.
Well, to learn the simple process to create your own service on Windows 10 or 7, we have chosen VirtualBox WebSRV as an example. In this way, we can learn both things. If we talk about VirtualBox Web service, it is available as
VBoxWebSrv.exe on Windows. This helps us to access the VirtualBox installed Virtual Machines over the network on some remote computer systems using client applications like RemoteBox.
With this tutorial, you will be able to run any application executable file service in the background and even can start it with the Windows boot. Although Windows has an inbuilt command-line tool called Sc.exe, however, the creating and running services from it is not an easy job for newbies.
However, the general syntax to create service with SC.exe tool of Microsoft is:
sc create <service name> binpath= <executable file path> type= own start= auto
sc create myVboxweb binpath= "C:\PROGRA~1\\Oracle\VirtualBox\VBoxWebSrv.exe" type= own start= auto
But the problem is you cannot use the above tool to create any executable as service, it must be an executable of Windows Service. Thus, when we run the above command it will successfully create the service but at the time to start, it will through an
Error 1053: The service did not respond to the start or control request in a timely fashion.
Hence, to make all this simple and easy to use for everyone here we use a third-party tool called NSSM.
1. Download NSSM- the Non-Sucking Service Manager
NSSM is a small tool that lets users create service of various applications on Windows. It is open-source easily available on the official website for free usage. It comes with both GUI and Command line support. Furthermore, NSSM monitors the running service and will restart it if it dies. Here is the link to download its zipped folder. However, the best way to install it using chocolatey.
Right-click on Windows Start button and select Windows PowerShell (Admin) and run the following commands:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
Close PowerShell and Start it again.
The above command will enable the Chocolatey on your system that we can use to install various Windows software with just one command.
Now, install NSSM on your system:
choco install nssm
2. Run NSSM to create VirtualBox Web Service
The next thing is to install a service for the VirtualBox web or any other executable file you want. On PowerShell or Command Prompt type:
nssm.exe install <service-name>
You can give the Service name whatever you want. Here we are creating a service with a name-
vboxweb, thus the command will be:
nssm.exe install vboxweb
This will open the GUI of Non-Sucking Service Manager to easily add the path of the executable file.
3. Add VBoxwebserv.exe file path
Now, you will see the GUI interface of NSSM, click on the (…) three dots given in the front of Path option to select the .exe file of the application you want to add as a service in Windows. You even copy-paste the path as well.
For VBox use this path:
4. Set Login details
Some installed application works under specifics users. For example, my VirtualBox has been installed for my user and works only for that. Thus, it would be great, if you provide the user credentials to service.
- Select “This Account”
- Enter your Windows username.
- Then type password two times for the username you mentioned above.
- Finally, click on the Install Service button.
5. Open Windows Service Manager
services.msc to open Windows Service Manager on PowerShell or Command Prompt. Alternatively, you can search for “Service” in the Windows 10 or 7 search box and click on its icon when it appears.
On Windows Service Manager you will see a lot of services in a stopped and running state. Search for the one you have created. For example, here we have installed a service called “Vboxweb“, thus simply press V to jump to that letter running services. Select the one you have created and click the Start link given on the left side.
In this way, we can create our own service manually on Windows systems. Moreover, once the VirtualBox Web service is started running you use the tools like RemoteBox for accessing your VM Guests from remote Linux or Windows machines over network: