0

I am coding my first windows service, in python and have a few issues. I am including only the part of the code up until the issue

Logon_Service.py

class EditService (win32serviceutil.ServiceFramework):
    _svc_name_ = "Edit Login Service"
    _svc_display_name_ = "Edit Login Service"

    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.stop_event = win32event.CreateEvent(None,0,0,None)
        socket.setdefaulttimeout(60)
        self.stop_requested = False

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.stop_event)
        logging.info('Stopping service ...')
        self.stop_requested = True

    def SvcDoRun(self):
        servicemanager.LogMsg(
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            servicemanager.PYS_SERVICE_STARTED,
            (self._svc_name_,'')
        )
        self.main()

    def main(self):
        while 1:
            if self.stop_requested:
                logging.info('A stop signal was received, breaking loop')
                break

            repo = AvidRepo(r"C:\Users\Administrator\Desktop\WorkGroups",r"C:\LogonTemp")
            repo.downloadSettings()
            repo.validateSettings()


            db = r"C:\Users\Administrator\Desktop\WorkGroups\test.db"

            key = repo.workgroupRegKey

            listofvalues = read_registry(key)
            currentWorkgroup = [f for f in listofvalues if f.startswith(r"/Avid/Workgroup-")]

            #if list index out of range

            groupNumber = currentWorkgroup[0][-2:]

            #Update Current Workgroup File
            currentWorkgroupFile = os.path.join(os.path.join(repo.repoDestination,"WG"+groupNumber),r"Workgroup\AvidWorkgroup.txt")
            shutil.move(currentWorkgroupFile,repo.workgroupFile)

            #Update Current BGInfo File
            currentBGInfo = os.path.join(os.path.join(repo.repoDestination,"WG"+groupNumber),r"BGINFO\x64Client.bgi")
            shutil.move(currentBGInfo,repo.bgLocation)
            time.sleep(5)
            #Execute New BGInfo File

            dir= ""
            cmd = r"cmd C:\BGInfo\Bginfo.exe /ic:\BGinfo\x64Client.bgi /timer:0 /silent /NOLICPROMPT"


            ret = call(cmd)

Service does not stop cleanly - and the subprocess.call() command does not work as well. When stopping the service, it continuously tries until it times out. the subprocess.call works from external to the service, but not in the service.

ANy ideas?

Busturdust
  • 2,447
  • 24
  • 41
  • 1
    Why are you using `r"cmd C:\BGInfo\Bginfo.exe ..."`? I see no reason to use the cmd shell there, plus even if you did it requires `/c`, e.g. `cmd /c command_to_run`, which is more easily accomplished via the `shell=True` argument of `subprocess.call`. – Eryk Sun Aug 21 '15 at 07:36
  • 1
    Also, in Windows Vista and later services are run in the non-interactive services session (i.e. session 0), so there's no desktop background for [Bginfo](https://technet.microsoft.com/en-us/library/bb897557.aspx) to modify. You can try the `/all` option to update the desktop background of all interactive sessions. – Eryk Sun Aug 21 '15 at 07:37
  • Thanks @eryksun i will look into it. and the cmd was in there as testing and I forgot to take it, I was testing lots of different combos -_-. Heading to work soon to get back into it – Busturdust Aug 21 '15 at 11:19
  • @eryksun what exactly do you mean by /all are you suggesting to add it to the end of the subprocess.call ? – Busturdust Aug 21 '15 at 11:28
  • @eryksun Didn't work, tried setting it to interactive etc., nothing, Im skipping this part of the reqs right now, as I have other environment issues (service not responding to start/stop commands from net/sc) bigger issues for now :( – Busturdust Aug 21 '15 at 13:41
  • Create a minimal, complete example. That makes it a lot easier for other people to help you. You may even solve your own problem in the process of whittling it down. – Eryk Sun Aug 21 '15 at 14:23
  • @eryksun I am opening a new question after reworking the service, http://stackoverflow.com/questions/32142907/python-windows-service-not-responding-to-start-stop-from-built-exe-but-works Im super head banging at this point haha – Busturdust Aug 21 '15 at 14:29

0 Answers0