0% found this document useful (0 votes)
43 views1 page

To run a Python script as a Windows

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

To run a Python script as a Windows

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

To run a Python script as a Windows service without using Windows Task Scheduler,

you can use a third-party tool like NSSM (Non-Sucking Service Manager). NSSM allows
you to run any executable (including Python scripts) as a Windows service.

Here are the steps to use NSSM to run a Python script as a Windows service at a
certain time:

Download NSSM from the official website (https://nssm.cc/download) and extract the
ZIP file to a folder.

Open Command Prompt as an administrator and navigate to the folder where you
extracted NSSM.

Use the following command to install the Python script as a service:

Copy code
nssm install <ServiceName>

Replace <ServiceName> with the name of your service.

In the NSSM installation window, specify the following:


Path: The full path to the Python executable (e.g. C:\Python\python.exe)
Startup directory: The full path to the folder where your Python script is located
Arguments: The full path to your Python script and any arguments it requires (e.g.
C:\MyScripts\MyScript.py --arg1 value1 --arg2 value2)
Display name: The name of your service as it will appear in the Services list
Description: A description of your service
Click the "Install service" button to install the service.

Use the following command to set the service to start automatically:

Copy code
nssm set <ServiceName> Start SERVICE_AUTO_START

Replace <ServiceName> with the name of your service.

Use the following command to set the service to start at a specific time:

Copy code
nssm set <ServiceName> StartTrigger Daily <StartTime>

Replace <ServiceName> with the name of your service and <StartTime> with the time
you want the service to start (in HH:MM format, using 24-hour time).

That's it! Your Python script will now run as a Windows service at the specified
time. You can use the standard Windows Service Manager to start, stop, or restart
the service.

You might also like