資源描述:
《VC編寫Windows服務(wù)程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、#include#include#includeTCHARszServiceName[]=_T("MyTestService");DWORDdwThreadID;HANDLEhEvent=INVALID_HANDLE_VALUE;SERVICE_STATUSstatus;SERVICE_STATUS_HANDLEhServiceStatus;voidInit();BOOLIsServiceInstalled();BOOLInstallService();BOOL
2、UninstallService();BOOLServiceCtrlStart();BOOLServiceCtrlStop();voidWINAPIServiceMain();voidWINAPIServiceStrl(DWORDdwOpcode);voidLogEvent(LPCTSTRpszFormat,...);//Usuage//Installservice://TestService.exe/install//Uninstallservice://TestService.exe/uninstall//Star
3、tservice://TestService.exe/start//Stopservice://TestService.exe/stopintmain(intargc,char*argv[]){????Init();????dwThreadID=::GetCurrentThreadId();????SERVICE_TABLE_ENTRYst[]=????{????????{szServiceName,(LPSERVICE_MAIN_FUNCTION)ServiceMain},????????{NULL,NULL}???
4、?};????LPSTRlpCmdLine=argv[1];????if(argc==2)????{????????BOOLbRet;????????if(stricmp(lpCmdLine,"/install")==0)????????{?????????????bRet=InstallService();?????????????if(bRet==TRUE)?????????????{??????????????????printf("Installservice%ssuccess",szServiceName);
5、?????????????}else?????????????{??????????????????printf("Installservice%sfailed",szServiceName);?????????????}????????}????????elseif(stricmp(lpCmdLine,"/uninstall")==0)????????{?????????????bRet=UninstallService();?????????????if(bRet==TRUE)?????????????{?????
6、?????????????printf("Uninstallservice%ssuccess",szServiceName);?????????????}else?????????????{??????????????????printf("Uninstallservice%sfailed",szServiceName);?????????????}????????}elseif(stricmp(lpCmdLine,"/start")==0)????????{?????????????bRet=ServiceCtrlS
7、tart();?????????????if(bRet==TRUE)?????????????{??????????????????printf("Startservice%ssuccess",szServiceName);?????????????}else?????????????{??????????????????printf("Startservice%sfailed",szServiceName);?????????????}????????}elseif(stricmp(lpCmdLine,"/stop"
8、)==0)????????{?????????????bRet=ServiceCtrlStop();?????????????if(bRet==TRUE)?????????????{??????????????????printf("Stopservice%ssuccess",szServiceName);????????????