快速开发window服务器程序

import service;


service.startDispatchThread( 
    服务名 = function(serviceName,argv){
        import service; 
        var srvStatus = service.registerCtrlThread(serviceName,function(control,eventType,pEventData){ 
            import service; 
            if( control == 0x1/*_SERVICE_CONTROL_STOP*/ ){  
                service.updateStatus({currentState = 0x1/*_SERVICE_STOPPED*/},owner.serviceName); 
            } 
        } )
        
        srvStatus.controlsAccepted = 0x1/*_SERVICE_ACCEPT_STOP*/
        srvStatus.currentState = 0x4/*_SERVICE_RUNNING*/;
        service.updateStatus(srvStatus,serviceName)
         
        import string;
        
        while(true){
        	var tm = time.now();
        	var str  = tostring(tm,"%Y年%m月%d日 %H时%M分%S秒","chs")
        	 string.save("E:/1.log",str ,true);
        	 sleep(1000);
        }
        srvStatus.controlsAccepted = 0;
        srvStatus.currentState = 0x1/*_SERVICE_STOPPED*/
        service.updateStatus(srvStatus,serviceName)
    }
)

 while() 里面是服务监控的代码

 

假设我们编译好了程序,在F 盘,名为test.exe ,使用SC.exe 工具(VS2005 : Microsoft Visual Studio 8/Common7/Tools/Bin/winnt )命令行下:
sc create Memorymonitor binPath= f:/test.exe

posted @ 2016-06-03 18:15  EchoSong  阅读(435)  评论(0编辑  收藏  举报