简体   繁体   English

开始服务?

[英]Starting a service?

Well, I've recently been getting into developing drivers, so I thought I should make a class to programmatically start services. 好吧,我最近开始研究驱动程序,所以我认为我应该上一堂课,以编程方式启动服务。 But of course, I ran into some trouble on the way, as usual. 但是,当然,像往常一样,我在途中遇到了一些麻烦。

I'm using StartService to start it, but for some reason it just hangs, I've done some research over the internet and it seems it waits for ensurance from the ServiceMain function to tell the control manager that the service has successfully initialized and is now running. 我正在使用StartService来启动它,但是由于某种原因它只是挂起了,因此我已经在Internet上进行了一些研究,看来它正在等待ServiceMain函数的保证,以告知控制管理器该服务已成功初始化并且正在运行。现在正在运行。

The problem is, nothing seems to be working, I've initialized the ServiceMain function using StartServiceCtrlDispatcher() but it never seems to be called, I've inserted some code into the servicemain function to ensure it's being called, and it isn't for some odd reason. 问题是,似乎什么都没用,我已经使用StartServiceCtrlDispatcher()初始化了ServiceMain函数,但似乎从未调用过,我已经在servicemain函数中插入了一些代码以确保它被调用了,但是没有由于某些奇怪的原因。

I've made sure no other function in the process is failing, CreateService returns success, as does OpenService, but as soon as I get to StartService, it hangs, and the only way it'll let me call StartService again is after I reboot. 我确保过程中没有其他功能失败,CreateService和OpenService一样都返回成功,但是一旦我进入StartService,它就会挂起,并且让我再次调用StartService的唯一方法是在重新启动后。

So, I guess what I'm asking is, if there are any simple explanations of how I can fix this, maybe some code if you guys don't mind. 所以,我想我要问的是,是否有关于如何解决此问题的简单解释,如果您不介意的话,可能是一些代码。

Thanks in advance. 提前致谢。 Much appreciated. 非常感激。

I believe there is plenty of example code here :) 我相信有很多的例子代码在这里 :)

Generally speaking though, if StartService is hanging, it's because you gave it garbage data. 一般来说,如果StartService挂起,那是因为您给了它垃圾数据。 No matter how badly behaved the service in question is, StartService should return immediately. 不管所讨论的服务的行为有多么糟糕, StartService都应立即返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM