问题
I want to prevent Windows XP from powering down as long as my Delphi app is running, and I tried the following:
procedure TForm1.FormCreate(Sender: TObject);
begin
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, nil, 0);
SystemParametersInfo(SPI_SETPOWEROFFACTIVE, 0, nil, 0);
SystemParametersInfo(SPI_SETLOWPOWERACTIVE, 0, nil, 0);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, nil, 0);
SystemParametersInfo(SPI_SETPOWEROFFACTIVE, 1, nil, 0);
SystemParametersInfo(SPI_SETLOWPOWERACTIVE, 1, nil, 0);
end;
but that doesn't seem to work. Other suggestions anyone?
TIA
Steven
回答1:
Here is the answer to your question:
Detecting and preventing Windows shut down http://delphi.about.com/cs/adptips2000/a/bltip0500_4.htm
回答2:
I have no Delphi knwoledge at all, but simply from a user's point of view: I don't want programs to be able to that and I would be seriously mad at microsoft if they allowed it.
Just think about it, with that ability any malicious software would disallow you to shut down as long as it is running, and it won't shut down - ouch. From now on we will never again shut down windows, we'll always have to power off the computer, which is not good for hardware or software.
I am not saying it is not possible, but if I were making an OS, I would actively make it hard or even impossible for you to do so, as it has simply too much potential for abuse. As such, you may well find that even microsoft was of this opinion and did indeed not make possible.
来源:https://stackoverflow.com/questions/1184940/programmatically-prevent-windows-to-shutdown