关于Windows下服务的创建

asddg67 2006-11-09 09:02:22
最近在写一个关于服务的程序,程序执行了以后在服务的窗口中看见服务已经写进去了,但是却没办法启动,代码如下
SC_HANDLE schSCManager=NULL;
SC_HANDLE schService=NULL;

schSCManager = OpenSCManager(
NULL, // local machine
NULL, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights

if (schSCManager == NULL)
{
AfxMessageBox("OpenSCManager failed!");
}

LPCTSTR lpszBinaryPathName = "C:\\Program Files\\Thunder Network\\Thunder\\Thunder.exe";
LPCTSTR lpszDisplayName ="thunder";
schService = CreateService(
schSCManager, // SCManager database
"under", // name of service
lpszDisplayName, // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_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)
AfxMessageBox("CreateService failed!");
else
AfxMessageBox("CreateService successed!");

if (!StartService(
schService, // handle to service
0, // number of arguments
NULL) ) // no arguments
{
AfxMessageBox("StartService failed!");
}
else
{
AfxMessageBox("Service start pending!");
}
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);


需要包含的头文件
#include <windows.h>
#include <winsvc.h>

别的程序好像可以,但是自己指定的却没办法进行,希望大家帮忙
...全文
65 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧