C++服务程序代码怎么写(C++,编程语言)

时间:2024-05-02 06:28:35 作者 : 石家庄SEO 分类 : 编程语言
  • TAG :

    C%2B%2B%E6%9C%8D%E5%8A%A1%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81%E6%80%8E%E4%B9%88%E5%86%99

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++服务程序代码怎么写的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Python服务程序代码怎么写下一篇:

13 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18