ControlService()API创建服务的新实例 [英] ControlService() API creating a new instance of the service

查看:89
本文介绍了ControlService()API创建服务的新实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码停止该服务. ControlService() API正在调用该服务的OnStartService()处理程序.因此,创建服务的新实例.

I am using the following code to stop the service. ControlService() API is giving call to OnStartService() handler of the service. Hence creating a new instance of the service.

// Open a connection to the SCM
    scm = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
    csMsg.LoadString(IDS_INOPENSCMGR);	
    // Get the service's handle
    service = OpenService(scm, SERVICE_NAME,
        SERVICE_ALL_ACCESS | DELETE);
                
    success = ControlService(service, SERVICE_CONTROL_STOP,&status);


有什么方法可以防止ControlService() API不能像这样.
谢谢,
Sunil


Is there some way to prevent ControlService() API not to behave like this.
Thanks,
Sunil

推荐答案

您是否正在使用某些包装器类?如果是这样,您需要提及.

如果您没有使用一个,而是使用直接API,则在ServiceCtrlHandler 中,您需要适当地处理它.我的一篇文章中的示例代码:

Are you using some wrapper class? If so you need to mention that.

If you are not using one, and you are using straight API, then in your ServiceCtrlHandler you need to handle that appropriately. Example code from one of my articles:

switch(nControlCode)
{	
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
	nServiceCurrentStatus=SERVICE_STOP_PENDING;				
	success=UpdateServiceStatus(SERVICE_STOP_PENDING,NO_ERROR,0,1,3000);
	KillService();		
	return;
default:
	break;
}



这是文章:

初学者的编写,安装,启动,停止NT服务的入门指南 [



Here''s the article:

Beginner''s introductory guide to writing, installing, starting, stopping NT services[^]

Once again, if you are using some wrapper class then you need to look at how you need to specially handle service termination (via the API exposed by the wrapper).


这篇关于ControlService()API创建服务的新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆