C++服务程序代码怎么写
导读:本文共3580字符,通常情况下阅读需要12分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: VOID Install(char *path, char *internalName, char *descriptiveName);VOID UnInstall(char *internalName);int main(int argc,char *argv[]){ char *install="install"; char *u... ...
目录
(为您整理了一些要点),点击可以直达。VOID Install(char *path, char *internalName, char *descriptiveName);
VOID UnInstall(char *internalName);
schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if (schSCManager == NULL)
printf("ERROR on OpenSCManager/n");
lpszDisplayName = TEXT(descriptiveName);
lpszBinaryPathName = path;
schService = CreateService(
schSCManager, /* SCManager database */
TEXT(internalName), /* name of service */
lpszDisplayName, /* service name to display */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS, /* service type */
SERVICE_AUTO_START, /* start type */
SERVICE_ERROR_NORMAL, /* error control type */
lpszBinaryPathName, /* service's binary */
NULL, /* no load ordering group */
NULL, /* no tag identifier */
NULL, /* no dependencies */
NULL, /* LocalSystem account */
NULL); /* no password */
if (schService == NULL)
printf("ERROR on CreateService/n");
else
printf("Service Installed/n");
CloseServiceHandle(schService);
exit(1);
}
VOID UnInstall(char *internalName)
{
SC_HANDLE schSCManager;
SC_HANDLE schService;
schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE);
schService = OpenService( schSCManager, TEXT(internalName), DELETE);
if (schService == NULL)
printf("OpenService failed/n");
if (! DeleteService(schService) )
printf("DeleteService FAILED/n");
else
printf("Service Removed/n");
CloseServiceHandle(schService);
exit(1);
}
---------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#define SLEEP_TIME 5000
#define LOGFILE "C://ywpturkey.txt"
////////////////////////////////////////////////////////////
// Declare several global variables to share
// their values across multiple functions of your program.
////////////////////////////////////////////////////////////
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
////////////////////////////////////////////////////////////
// Make the forward definitions of functions prototypes.
//
////////////////////////////////////////////////////////////
void ServiceMain(int argc, char** argv);
void ControlHandler(DWORD request);
int InitService();
// Service initialization
int InitService()
{
OutputDebugString("Monitoring started.");
int result;
result = WriteToLog("Monitoring started.");
return(result);
}
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
return;
case SERVICE_CONTROL_SHUTDOWN:
OutputDebugString("Monitoring stopped.");
WriteToLog("Monitoring stopped.");
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
return;
default:
break;
}
// Report current status
SetServiceStatus (hStatus, &ServiceStatus);
return;
}
C++服务程序代码怎么写的详细内容,希望对您有所帮助,信息来源于网络。