如何在python中从Windows服务运行外部应用程序?

时间:2015-11-08 00:26:53

标签: python windows service windows-services

我在python中有简单的Windows服务,我需要运行一些外部应用程序。我尝试使用os.systemsubprocess.call,但它在窗口服务中不起作用。

我的简单服务:

class AppServerSvc(win32serviceutil.ServiceFramework):
    _svc_name_ = "MyService1"
    _svc_display_name_ = "Test Service1"
    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):

        ########## That is my trial #################
        os.system("C:\\Windows\\System32\\notepad.exe")
        #############################################

        rc = None
        while rc != win32event.WAIT_OBJECT_0:
            rc = win32event.WaitForSingleObject(self.hWaitStop, 3000)

    if __name__ == '__main__':
        win32serviceutil.HandleCommandLine(AppServerSvc)

0 个答案:

没有答案