快速开发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
无生,无灭,看似最高境界