2010-12-27 4 views
6

私は以下のPythonのWin32サービスを作成しています。サービスをコンパイルするときにコードの断片ですが、services.mscに移動して手動で起動する必要があります。Pythonのwin32サービスがautomaticllyを開始

私はserivceをインストールするときにオプションがあります:myservice.exeをインストールすると自動的に起動しますか?以下

は、私のコードの抜粋です:

import win32serviceutil 
import win32service 
import win32event 

class SmallestPythonService(win32serviceutil.ServiceFramework): 
    _svc_name_ = "ser_name" 
    _svc_display_name_ = "ser_descryption" 
    #_svc_description_='ddd' 
    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): 

     win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) 

if __name__=='__main__': 

    win32serviceutil.HandleCommandLine(SmallestPythonService) 

答えて

1

あなたはcreateコマンドでsc.exeを使用することができます。

sc create MyPyService binPath= "C:\myservice.exe" DisplayName= "Some Python Service" 

詳細はMicrosoft KB251192です。

win32serviceutilには、使用できる可能性のあるInstallService()機能があります。

2

私はこのActiveState recipeを見ていきます。これは、サービスを自動起動する方法を示すwin32serviceutilのラッパーです。

6

を使用してサービスをインストールし、自動的に起動するように設定します。

+0

Nativソリューションは、最適なソリューションです! – enthus1ast

0

@Maciejgが私のために動作しません、ここではautomaticaly私のサービスを開始するためのソリューションはpy2exeで建てる:

myservice.exe -auto -install 
関連する問題