Autor Beitrag
JacK_Silent
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Sa 17.11.07 15:49 
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:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
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.


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.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.11.07 00:16 
Windows-Nachrichten können nicht Desktop-Übergreifend verschickt werden.

1. Welches OS?
2. Läuft der Service als "Desktop Interactive"?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
JacK_Silent Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: So 18.11.07 16:16 
System: WinXP Prof.

Anmeldung läuft über das Lokale Systemkonto und der Haken bei Datenaustausch zwischen Dienst und Desktop zulassen ist auch gesetzt. --> Desktop Interactive: ja

Es ist also nicht möglich, dass der Dienst im Lokale Systemkonto mitbekommt, weil der Ruhezustand auf meinen Desktop geleitet wird? oder gibt es doch eine Möglichkeit?

//edit: selbst, wenn der Dienst unter meinen Benutzernamen gestartet wird, dann schneidet er nicht mit, dass der PC in den Ruhezustand geht!