![]() |
Ruhezustand mit WindowsDienst abfangen oder abfragen
heyaaa =D
Ich hab einen Windows Dienst programmiert (mit der von Delphi gegeben Komponente "Service-Anwendung"). Allerdings lässt sich damit der Ruhezustand nicht abfragen! Folgender Code funktioniert bei einer normalen Form1:
Delphi-Quellcode:
Allerdings nicht in der Service Komponente! Er bringt zwar beim kompilieren keinen Fehler. Allerdings bekommt er auch nicht mit, dass der PC in den Ruhezustand geht.
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) private { Private-Deklarationen } public { Public-Deklarationen } procedure WMPowerBroadcast(var Msg: TMessage); message WM_POWERBROADCAST; end; const PBT_APMQUERYSUSPEND = $0000; PBT_APMQUERYSTANDBY = $0001; PBT_APMQUERYSUSPENDFAILED = $0002; PBT_APMQUERYSTANDBYFAILED = $0003; PBT_APMSUSPEND = $0004; PBT_APMSTANDBY = $0005; PBT_APMRESUMECRITICAL = $0006; PBT_APMRESUMESUSPEND = $0007; PBT_APMRESUMESTANDBY = $0008; PBTF_APMRESUMEFROMFAILURE = $00000001; PBT_APMBATTERYLOW = $0009; PBT_APMPOWERSTATUSCHANGE = $000A; PBT_APMOEMEVENT = $000B; PBT_APMRESUMEAUTOMATIC = $0012; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.WMPowerBroadcast(var Msg: TMessage); begin showmessage('PowerBroadcast erhalten'); if (Msg.WParam = PBT_APMSUSPEND) or (Msg.WParam = PBT_APMSTANDBY) then begin // windows want to go into standby or hibernation mode // Hier hin, was getan werden muss, bevor Windows in den Standby darf, // z.B. Netzwerk- oder Datenbankverbindungen trennen, Timer abstellen, etc. showmessage('Standby/Ruhezustand'); Msg.Result := 1; // allow standby/hibernation //Msg.Result := BROADCAST_QUERY_DENY; // deny standby/hibernation end else if (Msg.WParam = PBT_APMRESUMECRITICAL) or (Msg.WParam = PBT_APMRESUMESUSPEND) or (Msg.WParam = PBT_APMRESUMESTANDBY) then begin // windows returns from standby or hibernation // Hier z.B. Verbindungen wiederherstellen showmessage('Rückkehr aus Standby/Ruhezustand'); end; end; //inherited WndProc(MyMessage); end. |
Re: Ruhezustand mit WindowsDienst abfangen oder abfragen
Windows-Nachrichten können nicht Desktop-Übergreifend verschickt werden und schon gar nicht WindowsStations übergreifend.
1. Welches OS? 2. Läuft der Service als "Desktop Interactive"? |
Re: Ruhezustand mit WindowsDienst abfangen oder abfragen
Zitat:
Zitat:
Habe deinen Artikel über die Window Stations übrigens schon gelesen ( ![]() Ne Lösung für mein Problem hab ich allerdings nicht gefunden |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:00 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz