views:

72

answers:

1

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.

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.

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.

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.

A: 

I believe there is plenty of example code here :)

Generally speaking though, if StartService is hanging, it's because you gave it garbage data. No matter how badly behaved the service in question is, StartService should return immediately.

Billy ONeal
Billy, that was the first place I looked, I tried re writing that to fit my needs but it wasn't working. As I said, the ServiceMain function isn't even being called for some reason.
Davidm44
Well the first call to StartService seems to be working, and in the list of services I can see mine running, so it's obviously not garbage. Or is there something more to this that I'm missing?
Davidm44
@Davidm44: I thought you said `StartService` was hanging? I'm confused by what you mean here.
Billy ONeal
It does hang, but it gets the service running, BUT, now that its hanging, it won't let me call it anymore.
Davidm44
@Davidm44: Even if it seems to work, if it's hanging. that's indicative of other problems. StartService returns immediately.
Billy ONeal
So, are you saying there is something with my service or something with my program trying to start the service? If it's the service, what should I do to prevent this from happening? All it is right now is a basic function ( the entry point ).
Davidm44
@Davidm44 -- If the call to `StartService` does not return immediately, regardless of the correctness or incorrectness of the service itself, the program starting the service put incorrect data into `StartService` (because `StartService` returns instantly under normal conditions) If something inside the service itself is hanging I do not understand your question.
Billy ONeal
Hmm, the only information I'm giving is the handle to the service, which I got from OpenService, which returned successfully. The other 2 parameters are NULL, what incorrect data could I be giving? Thanks for replying by the way.
Davidm44
Davidm44