I have created a windows service in python and then convert it into an exe file and install that exe file as a windows service using this command :
sc create PC-Service binpath= "C:\\Users\\Slazenger\\Desktop\\auto-py-to-exe-master\\output\\testing.exe" DisplayName= "PC-Service" start=auto
and i got success message
[SC] CreateService SUCCESS
But when i tried to install service with this command:
sc start PC-Service
I got this error message
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
I don't know why I am getting this because when i run my python script as a service it runs perfectly but when i tried to run exe file as a service i am getting error kindly help me. Here is my python script:
def WriteToFile():
while True:
file = open ( "C:\\file.txt" , "w" )
now = datetime.now()
now = now.strftime("%B %d, %y %H:%M:%S")
file.write(now)
class Pythonservice(win32serviceutil.ServiceFramework):
_svc_name_ = 'PC-Service'
_svc_display_name_ = 'PC-Service'
_svc_description_ = 'Freindly Service'
@classmethod
def parse_command_line(cls):
win32serviceutil.HandleCommandLine(cls)
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(60)
def SvcStop(self):
self.stop()
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
self.start()
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ''))
self.main()
def start(self):
self.isrunning = True
def stop(self):
self.isrunning = False
def main(self):
WriteToFile()
if __name__ == '__main__':
Pythonservice.parse_command_line()
Kindly help me to rid out of this Thank you.