Skip to content

Instantly share code, notes, and snippets.

@mastro35
Created July 30, 2018 13:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mastro35/28d77339656b92d14e7a020367717b2f to your computer and use it in GitHub Desktop.
Save mastro35/28d77339656b92d14e7a020367717b2f to your computer and use it in GitHub Desktop.
import time
import random
from pathlib import Path
from SMWinservice import SMWinservice
class PythonCornerExample(SMWinservice):
_svc_name_ = "PythonCornerExample"
_svc_display_name_ = "Python Corner's Winservice Example"
_svc_description_ = "That's a great winservice! :)"
def start(self):
self.isrunning = True
def stop(self):
self.isrunning = False
def main(self):
i = 0
while self.isrunning:
random.seed()
x = random.randint(1, 1000000)
Path(f'c:\\{x}.txt').touch()
time.sleep(5)
if __name__ == '__main__':
PythonCornerExample.parse_command_line()
@manojr2k
Copy link

manojr2k commented Aug 1, 2019

Thanks for the code , I able to create the service , service runs absolutly fine .
But when i run the below command from python script , its runnig fine from debug mode , but when i try to run from service its not executing , can you please tel me the exact reason for this?
command4 = '"D:\Prognocis\Backup\robocopy.exe" ' + "/MIR W:\Formulary\FBS_3_0 D:\Formularylocal\Formulary_3_0 ."
os.system(command4)

@manojr2k
Copy link

Hi cervelle

thanks for the Link , I tried it , but its not working .
any other solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment