Shahzaib Nasir
Shahzaib Nasir

Reputation: 41

Creating a windows script using nssm

I have a python script that continuosuly runs and sends data via socket to a server. Now i want to create a service of that script exe that users donwload the script runs as a backgroung service without human intervention and automatically restarts when the system restarts.

I wanted to integrate it to my application but there are some auth issues and also the script had to be run manually again i want it to be like users downloads it once and all other work is automated .
Any tip, solution or resource would be appreciated.

Upvotes: 1

Views: 137

Answers (1)

AsrtoMichi
AsrtoMichi

Reputation: 36

to create an exe from py program use Pyinstaller, whit -w flag to suppress the consol.

To start the program after rebooting you can create a batch file, that starts the .exe program, in the folder: C:\Users\%Username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup, to create file use that code:

from os import environ

open(f"c:\\Users\\{environ.get('USERNAME')}\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Program-launcher.bat", 'w').write(f"start {__file__}")

There are more elegant ways, but I prefer this one because it doesn't require you to be an admin, it doesn't require additional libraries and it doesn't mess around with system variables and it's very concise.

I hope I have understood the request well.

Upvotes: 0

Related Questions