添加服务的C++代码
添加服务的C++代码
//文件名addserver.cpp
#include <stdio.h>
#include <windows.h>
#include <winsvc.h>char servername[100];
char serverinfo[100];
char serverpath[100];int main(void)
{
printf("请输入服务名:");
scanf("%s",&servername);printf("请输入服务描述:");
scanf("%s",&serverinfo);printf("请输入程序路径:");
scanf("%s",&serverpath);SC_HANDLE manager=NULL;
SC_HANDLE service=NULL;if((manager=OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE))==NULL)
{
printf("服务打开出错");
}
service=CreateService(manager,servername,serverinfo,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
serverpath, 0, 0, 0, 0, 0 );if(service)
printf("创建成功 ");
else
printf("创建失败 ");CloseServiceHandle(service);
CloseServiceHandle(manager);return 0;
}
补充:软件开发 , C++ ,