2025-12-17 15:54:50 +01:00
|
|
|
|
#ifndef SERVICE_WRAPPER_H
|
2025-11-23 18:13:39 +01:00
|
|
|
|
#define SERVICE_WRAPPER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
2025-12-02 21:45:43 +01:00
|
|
|
|
typedef struct MyService {
|
2025-12-05 17:40:12 +01:00
|
|
|
|
char Name[256];
|
|
|
|
|
|
char Display[256];
|
|
|
|
|
|
char Description[512];
|
2025-12-02 21:45:43 +01:00
|
|
|
|
} MyService;
|
|
|
|
|
|
|
2025-12-11 11:00:52 +01:00
|
|
|
|
typedef void (*ServiceLogFunc)(const char* message);
|
|
|
|
|
|
|
2025-11-23 18:13:39 +01:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
# 停止服务
|
|
|
|
|
|
net stop RemoteControlService
|
|
|
|
|
|
|
|
|
|
|
|
# 查看状态(应该显示 STOPPED)
|
|
|
|
|
|
sc query RemoteControlService
|
|
|
|
|
|
|
|
|
|
|
|
# 启动服务
|
|
|
|
|
|
net start RemoteControlService
|
|
|
|
|
|
|
|
|
|
|
|
# 再次查看状态(应该显示 RUNNING)
|
|
|
|
|
|
sc query RemoteControlService
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-12-02 21:45:43 +01:00
|
|
|
|
// 自定义服务信息
|
2025-12-11 11:00:52 +01:00
|
|
|
|
void InitWindowsService(MyService info, ServiceLogFunc log);
|
2025-12-02 21:45:43 +01:00
|
|
|
|
|
|
|
|
|
|
// 以Windows服务模式运行程序
|
|
|
|
|
|
BOOL RunAsWindowsService(int argc, const char* argv[]);
|
2025-11-23 18:13:39 +01:00
|
|
|
|
|
|
|
|
|
|
// 检查服务状态
|
|
|
|
|
|
// 参数:
|
|
|
|
|
|
// registered - 输出参数,服务是否已注册
|
|
|
|
|
|
// running - 输出参数,服务是否正在运行
|
|
|
|
|
|
// exePath - 输出参数,服务可执行文件路径(可为NULL)
|
|
|
|
|
|
// exePathSize - exePath缓冲区大小
|
|
|
|
|
|
// 返回: 成功返回TRUE
|
|
|
|
|
|
BOOL ServiceWrapper_CheckStatus(BOOL* registered, BOOL* running,
|
2025-11-29 23:22:55 +01:00
|
|
|
|
char* exePath, size_t exePathSize);
|
2025-11-23 18:13:39 +01:00
|
|
|
|
|
|
|
|
|
|
// 简单启动服务
|
|
|
|
|
|
// 返回: ERROR_SUCCESS 或错误码
|
|
|
|
|
|
int ServiceWrapper_StartSimple(void);
|
|
|
|
|
|
|
|
|
|
|
|
// 运行服务(作为服务主入口)
|
|
|
|
|
|
// 返回: ERROR_SUCCESS 或错误码
|
|
|
|
|
|
int ServiceWrapper_Run(void);
|
|
|
|
|
|
|
|
|
|
|
|
// 安装服务
|
2025-12-02 21:45:43 +01:00
|
|
|
|
BOOL ServiceWrapper_Install(void);
|
2025-11-23 18:13:39 +01:00
|
|
|
|
|
|
|
|
|
|
// 卸载服务
|
2025-12-11 11:00:52 +01:00
|
|
|
|
BOOL ServiceWrapper_Uninstall(void);
|
2025-11-23 18:13:39 +01:00
|
|
|
|
|
|
|
|
|
|
// 服务工作线程
|
|
|
|
|
|
DWORD WINAPI ServiceWrapper_WorkerThread(LPVOID lpParam);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SERVICE_WRAPPER_H */
|