S
Sun_
Unregistered / Unconfirmed
GUEST, unregistred user!
如下面的程序,我想打开"Rising Realtime Monitor Service"服务,但经调试,
在OpenService时失败。请大家帮帮忙,程序应如何修正?
//////////////////////////////////////////////////////////////////////
//file: WinService.H
#include<WINDOWS.H>
//class CWinService
class CWinService
{
private:
LPCTSTR lpServiceName;
public:
CWinService(LPCTSTR lpServiceName);
BOOL Start(void)const;
};
//initialize ServiceName
CWinService::CWinService(LPCTSTR ServiceName):lpServiceName(ServiceName)
{
}
//start the service
BOOL CWinService::Start(void)const
{
BOOL ret=false;
LPCTSTR* lpSAV;
SC_HANDLE hSC;
SC_HANDLE hSCM=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if(hSCM!=NULL)
{
hSC=OpenService(hSCM,lpServiceName,SERVICE_START);
if(hSC!=NULL)
ret=StartService(hSC,0,lpSAV);
CloseServiceHandle(hSC);
}
CloseServiceHandle(hSCM);
return ret;
}
//////////////////////////////////////////////////////////////////////
//file: test.cpp
#include"WinService.h"
void main(void)
{
//"Rising Realtime Monitor Service"是我想启动的服务名
CWinService RavService("Rising Realtime Monitor Service");
RavService.Start();
}
在OpenService时失败。请大家帮帮忙,程序应如何修正?
//////////////////////////////////////////////////////////////////////
//file: WinService.H
#include<WINDOWS.H>
//class CWinService
class CWinService
{
private:
LPCTSTR lpServiceName;
public:
CWinService(LPCTSTR lpServiceName);
BOOL Start(void)const;
};
//initialize ServiceName
CWinService::CWinService(LPCTSTR ServiceName):lpServiceName(ServiceName)
{
}
//start the service
BOOL CWinService::Start(void)const
{
BOOL ret=false;
LPCTSTR* lpSAV;
SC_HANDLE hSC;
SC_HANDLE hSCM=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if(hSCM!=NULL)
{
hSC=OpenService(hSCM,lpServiceName,SERVICE_START);
if(hSC!=NULL)
ret=StartService(hSC,0,lpSAV);
CloseServiceHandle(hSC);
}
CloseServiceHandle(hSCM);
return ret;
}
//////////////////////////////////////////////////////////////////////
//file: test.cpp
#include"WinService.h"
void main(void)
{
//"Rising Realtime Monitor Service"是我想启动的服务名
CWinService RavService("Rising Realtime Monitor Service");
RavService.Start();
}