-
Download NSSM: First, you need to download the NSSM tool. You can download the latest version suitable for your system from the NSSM official website.
-
Extract NSSM: Extract the downloaded NSSM zip file to a location that is easily accessible to you.
-
Use NSSM GUI: Open the command prompt and navigate to the directory where NSSM was extracted. Then execute the following command to open the GUI.
nssm install MyService
-
Create a Service with NSSM: Open the command prompt and navigate to the directory where NSSM was extracted. Then execute the following command to create a service (if using the GUI, fill in the necessary fields as needed).
Here is an example with a Django application:
1
nssm install DjangoServer "C:\Users\AppData\Local\Programs\Python\Python312\python.exe" "C:\Users\Desktop\Django\manage.py" runserver 127.0.0.1:6969
-
Configure the Service: NSSM will pop up a GUI window where you can configure various properties of the service, such as startup type, working directory, etc. Ensure you set the appropriate parameters and click the “Install service” button to install the service. You can also configure the working directory using the command line:
nssm set DjangoServer AppDirectory "C:\Users\Desktop\Django"
-
Start the Service: Start the newly created service using NSSM or the command line:
net start DjangoServer
-
View Running Services: You can use the sc command in the command prompt to view currently running services. Here are some commonly used sc commands:
1 2 3 4 5
sc query # Lists the status information of all services. sc queryex <service_name> # Displays detailed information about a specified service. sc start <service_name> # Starts a specified service. sc stop <service_name> # Stops a specified service. sc config <service_name> start= <start_type> # Modifies the startup type of a specified service.
Example: To view the status information of all services, execute the following command:
sc query
To view detailed information of a specific service, execute:
sc queryex DjangoServer
To start a service:
net start DjangoServer
To stop a service:
sc stop DjangoServer
To delete a service:
sc delete DjangoServer