捡分了!!!请问怎样把VC生成的服务程序EXE添加到NT系统服务中??? 我在VC下做了一个后台服务的程序,生成一个EXE文件,请问怎样把EXE添加到NT 的系统服务中进行管理呢,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MSDN Creating a Simple Win32 Service in C++ 有说明 TCHAR szPath[512]="c:\\service\\ReplServer.exe"; schSCManager = OpenSCManager( NULL, // machine (NULL == local) NULL, // database (NULL == default) SC_MANAGER_ALL_ACCESS // access required ); if ( schSCManager ) { schService = OpenService( schSCManager, // SCM database TEXT(SZSERVICENAME), // service name SERVICE_ALL_ACCESS); Sleep(3000); if (schService == NULL) { ErrMsg=""; ErrMsg=ErrMsg+"OpenService failed -"+GetLastErrorText(szErr, 256); ::AfxMessageBox(ErrMsg); } if (!QueryServiceStatus( schService, // handle to service &ssStatus) ) // address of status information ::AfxMessageBox(GetLastErrorText(szErr, 256)); if (ssStatus.dwCurrentState != SERVICE_RUNNING) { m_TrayIcon.SetIcon(IDI_STOP); if(!StartService(schService,0,NULL)) ::AfxMessageBox(GetLastErrorText(szErr, 256)); else m_TrayIcon.SetIcon(IDI_START); } else m_TrayIcon.SetIcon(IDI_START); CloseServiceHandle(schService); CloseServiceHandle(schSCManager); } 如果是用atl 模板只要启动程序时加上参数 -service 就安装上了, 如果用其他方法制作的就看自己怎样定义了 mfkzj() 说得对,用控制台!!自己添加,具体函数说明可以看看MSDN下的函数介绍! 对话框界面问题 如何让窗体放在最前 net2003正常安装却不能打开IDE 我在用到创建桌面快捷方式的时候遇到了问题,为什么要初始化COM组建?我没有用过 添加或删除数据后,怎样让DataGrid立刻更新并显示出来? 为什么贴的BMP图片会错位? Visual C++ IDE环境总是自动关闭 翻译HTML编码的问题 200分,寻找Active 专家,Active的发布,下载,服务器端调用,客户端浏览器的调用! 如果我有Windows 98 的原代码你准备出多少钱? 简单listbox问题 100问一个超简单的新建窗口的问题,马上给分!!UP有分!
schSCManager = OpenSCManager(
NULL, // machine (NULL == local)
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
);
if ( schSCManager )
{
schService = OpenService(
schSCManager, // SCM database
TEXT(SZSERVICENAME), // service name
SERVICE_ALL_ACCESS);
Sleep(3000);
if (schService == NULL)
{
ErrMsg="";
ErrMsg=ErrMsg+"OpenService failed -"+GetLastErrorText(szErr, 256);
::AfxMessageBox(ErrMsg);
}
if (!QueryServiceStatus(
schService, // handle to service
&ssStatus) ) // address of status information
::AfxMessageBox(GetLastErrorText(szErr, 256));
if (ssStatus.dwCurrentState != SERVICE_RUNNING)
{
m_TrayIcon.SetIcon(IDI_STOP);
if(!StartService(schService,0,NULL))
::AfxMessageBox(GetLastErrorText(szErr, 256));
else
m_TrayIcon.SetIcon(IDI_START);
}
else
m_TrayIcon.SetIcon(IDI_START);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
}