文件名称:使用vc创建删除windows服务
文件大小:78KB
文件格式:RAR
更新时间:2019-02-19 08:42:32
vc 创建
// Register the control request handler status.dwCurrentState = SERVICE_START_PENDING; status.dwControlsAccepted = SERVICE_ACCEPT_STOP; //注册服务控制 hServiceStatus = RegisterServiceCtrlHandler(szServiceName, ServiceStrl); if (hServiceStatus == NULL) { LogEvent(_T("Handler not installed")); return; } SetServiceStatus(hServiceStatus, &status); status.dwWin32ExitCode = S_OK; status.dwCheckPoint = 0; status.dwWaitHint = 0; status.dwCurrentState = SERVICE_RUNNING; SetServiceStatus(hServiceStatus, &status); //模拟服务的运行,10后自动退出。应用时将主要任务放于此即可 int i = 0; while (i < 10) { Sleep(1000); i++; } // status.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(hServiceStatus, &status); LogEvent(_T("Service stopped")); }
【文件预览】:
testWS
----ServiceTest.dsw(547B)
----ServiceTest.dsp(4KB)
----ServiceTest.cpp(8KB)
----ReadMe.txt(1KB)
----copyright.bat(173B)
----StdAfx.cpp(298B)
----ServiceTest.ilk(190KB)
----StdAfx.h(773B)
----ServiceTest.plg(2KB)
----ServiceTest.exe(160KB)