Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with service application

Status
Not open for further replies.

abcfantasy

Programmer
Jun 3, 2006
110
DK
I've made this application that detects windows shutdown and stops it. I did this using the following procedure:

Code:
procedure TMyForm.WMQueryEndSession(var Msg: TWMQueryEndSession);
begin
  Msg.Result := 0;
end;

It worked correctly on a normal application. But as a service application, it does not work (does not even enter the procedure). I did install and start the service.

Any help is appreciated
Thanks in advance
Andrew

ABC -
 
Hi,

this is standard behaviour:
your service does not receive messages when the 'allow service to interact with desktop' option is not checked in the service properties.

there is a solution:
the TService object provides an event called onShutDown.

so you can do this:

Code:
// add this handler to the onshutdown event
procedure TSvc_test.ServiceShutdown(Sender: TService);

var Stopped : boolean;

begin
 // is called when windows shuts down
 ServiceStop(Self, Stopped);
end;

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Wait so if interactive is set to true, it should recieve windows messages? It did not work in that way either.

As for the solution you proposed, for some reason I don't think it's even going into the procedure. I've got a showmessage but its not being displayed (should work when interactive is set to true right?).

Last thing is how do i stop windows shutdown in that way?

Thanks for your quick reply

ABC -
 
Anyone?

The following works for detecting shutdown:

Code:
function CtrlHandler(CtrlType:DWORD):BOOL; stdcall;
begin
  Result:= False;
  case CtrlType of
    CTRL_LOGOFF_EVENT:
    begin
       ...
    end;
  end;
end;

but is there way to stop shutdown in that way?

Also I've heard about services recieving a SERVICE_CONTROL_SHUTDOWN notification. Anyone knows more on how to use this?

Help is appreciated
Thanks

ABC -
 
its not nice for a service preventing a shutdown, why do you want to do that?

anyway if the service is interactive, it should receive the
WMQueryEndSession message. setting msg.result to 0 will prevent shutting down windows. be aware that some tasks may already been shutdown prior to your service.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
The reason is that I need this program to detect and stop shutdown, then run an anti-spyware application (which shuts down the pc when complete).

I tried to search for ready made programs, but failed to find a suitable one. In one of them, you had to shut down the computer through that program (which is not practical for many users since they shutdown from the start menu). Another program kept on stopping shutdown when the anti-spyware app was ready, and re-run the app and so on.

So I'm making this to run the app once.

I've set Interactive to true but it's still not working for some reason. If I don't find a solution, I'll probably leave it as a normal application.

Just reply if you have any other suggestions
Thanks again
Andrew

ABC -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top