Autor Beitrag
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Sa 10.02.07 14:30 
Hi Leute!

Geht es irgendwie mit Delphi die Energieoptionen (Monitor ausschalten, Festplatten ausschalten, Standby, Ruhezustand) vorübergehend zu deaktivieren? Wichtig ist mir v.a. Monitor ausschalten, da die anderen bei mir sowieso deaktiviert sind.

Gruß

Calculon
--
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Sa 10.02.07 16:17 
Also ich hab' es bis jetzt so probiert:

ausblenden Delphi-Quelltext
1:
Setsystempowerstate(true, true);					

Hatte keinen Effekt!

und so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
   SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
end;

Also in einem Timer soll der Monitor immer wieder aktiviert werden (der Wert -1 ist nicht dokumentiert - ich habe ihn irgenwo über google aufgeschnappt). Funktioniert auch - aber nur ganz kurz. Der Monitor fing an zu blinken (an-aus-an-aus...).

Gruß

Calculon
--
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Sa 10.02.07 17:31 
Hi Calculon,

ich hab da mal ein Vorschlag. Ich habe in den Energieoptionen ein neues Energieschema eingefügt. Das geht auch mit der Funktion: WritePwrScheme.

Dann habe ich die Funktion SetActivePwrScheme verwendet um das neue Scheme zu verwenden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function SetActivePwrScheme(UINT: Integer;
                            PGLOBAL_POWER_POLICY: Integer;
                            PPOWER_POLICY: Integer): Boolean; stdcallexternal 'powrprof.dll';

procedure TForm1.Button1Click(Sender: TObject);
begin
 SetActivePwrScheme(600); // Das neue Scheme (bei mir an 6ter Position)
end;

Procedure TForm1.Button2Click(Sender: TObject);
begin
 SetActivePwrScheme(100); // Das alte Scheme (z.B. 0  bei mir 'Tragbar/Laptop')
end;


Die Position des Schemes kannst du in den Energieoptionen nachlesen.

Gruß

Saubäär
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Sa 10.02.07 17:40 
Danke für deine Mühen Saubäär!

Ich hab' in der Zwischenzeit aber einen Weg gefunden, der perfekt funktioniert (deaktiviert Screensaver und Abschaltung des Monitors, solange die Anwendung aktiv ist):

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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure WMSysCommand(var Msg : TWMSysCommand); message WM_SYSCOMMAND;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMSysCommand(var Msg : TWMSysCommand);
begin
  //catch the message and turn it off
  if (Msg.CmdType = SC_MONITORPOWER) or (Msg.CmdType = SC_SCREENSAVE) then
  begin
    Msg.Result := -1;
  end
  else
  inherited;///Otherwise do whatever is supposed to be done
end;

end.


Schönen Dank und Gruß

Calculon
--
HolgerMaune
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Mo 19.03.07 22:45 
Die Lösung funktioniert bei mir auch einwandfrei.
Ich habe nun folgendes Problem: Solange sich das Programm in einem bestimmten Zustand befindet soll die Abschaltung des Monitors verhindert werden.. Funktioniert einwandfrei. Das Problem kommt, wenn der Zustand verlassen wird: Der Monitor geht sofort aus.

Daher meine Frage:
Gibt es eine Möglichkeit den Timer für den Energiesparmodus zurückzusetzen?

P.S. Mit "SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1);" funktioniert es leider nicht.


Vielen Dank

Holger
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Mo 19.03.07 23:21 
Was meinst du mit bestimmten Zustand?

Ich habe hier ein Freewaretool hochgeladen. Wenn du willst kann ich dir den Code schicken!

Gruß

Calculon
--
wolke
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 240



BeitragVerfasst: Di 20.03.07 01:00 
Hier vielleicht noch ein hilfreicher Auszug aus den Sourcen meines Tools A.L.A.R.M.

Damit deaktiviere ich die Events "LidClose", "PowerButton" und "SleepButton" und stelle sie zu gegebenem Zeitpunkt wieder her.

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:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
{
 *************************************************************************
 * A.L.A.R.M. - A Laptop A/C Removal Monitor
 *
 * ALARM plays a sound file when A/C power is removed and the workstation
 * is locked.
 *
 * This source code is released under GPL. You are allowed to freely
 * use parts of it and modify them as long as you credit the author
 * and publish your derived work under GPL as well.
 * For full license information, check the included GPLlicense.txt
 * or http://www.gnu.org/copyleft/gpl.html
 *
 * (c) Moritz Bartl, software@wiredwings.com , http://www.wiredwings.com/
 *
 *************************************************************************

 * PowerScheme is responsible to save and restore the current power profile
 * and to disable the following power events:
 *
 * PowerButtonAc/Dc, SleepButtonAc/Dc, LidCloseAc/Dc
 *
 * See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/global_user_power_policy_str.asp
 *
 * Uses JEDI Win32API from http://www.delphi-jedi.org/
}


unit PowerScheme;

interface

uses JwaPowrProf, JwaWinNT;

type
  TPowerScheme = class
  private
    globalPowerPolicy: GLOBAL_POWER_POLICY;
    newGlobalPowerPolicy: GLOBAL_POWER_POLICY;
    powerPolicy: POWER_POLICY;
    pwrScheme: Cardinal;

    saved: boolean;
  protected
  public
    { Public declarations }
    procedure Disable;
    procedure Restore;
  end;

implementation

uses Dialogs, SysUtils;

procedure TPowerScheme.Disable;
begin
 saved := GetCurrentPowerPolicies(@globalPowerPolicy, @powerPolicy);
 if GetCurrentPowerPolicies(@newGlobalPowerPolicy, @powerPolicy) then
 begin
    newGlobalPowerPolicy.user.LidCloseAc.Action := PowerActionNone;
    newGlobalPowerPolicy.user.LidCloseDc.Action := PowerActionNone;
    newGlobalPowerPolicy.user.PowerButtonAc.Action := PowerActionNone;
    newGlobalPowerPolicy.user.PowerButtonDc.Action := PowerActionNone;
    newGlobalPowerPolicy.user.SleepButtonAc.Action := PowerActionNone;
    newGlobalPowerPolicy.user.SleepButtonDc.Action := PowerActionNone;
    GetActivePwrScheme(pwrScheme);
    SetActivePwrScheme(pwrScheme, @newGlobalPowerPolicy, nil);
// WriteGlobalPwrPolicy seems not be necessary here
    WriteGlobalPwrPolicy(newGlobalPowerPolicy);
 end;
end;

procedure TPowerScheme.Restore;
begin
 if saved then
 begin
    GetActivePwrScheme(pwrScheme);
    SetActivePwrScheme(pwrScheme, @globalPowerPolicy, nil);
// WriteGlobalPwrPolicy seems not be necessary here
    WriteGlobalPwrPolicy(globalPowerPolicy);
 end;
end;

end.
HolgerMaune
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Mi 21.03.07 23:12 
Kurz zur Beschreibung:

Ich habe eine Anzeige-SW entwickelt, die auf einem 40''-TFT läuft und nicht dauerhaft benötigt wird. Aus diesem Grund schicke ich den Bildschirm nach 30s in den Energiesparmodus. Das Verhindern des Starten des Energiesparmodus und des Bildschirmschoners funktioniert einwandfrei. Auch das Aufwecken. Ich hatte nun das Problem, dass der Timer für den Energiesparmodus abgelaufen war und ich mit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  if ((Msg.CmdType = SC_MONITORPOWER) or (Msg.CmdType = SC_SCREENSAVE)) and not aktiv then
  begin
    Msg.Result := -1;
  end


zwar das Starten des Energiesparmodus verhindern konnte, der Timer jedoch nicht zurückgesetzt wurde. Wurde das Programm jetzt nicht mehr benötigt, wird die var <aktiv> auf false gesetzt. Dies hatte zur Folge, dass der Bildschirm sofort eingeschlafen ist und nicht erst nach 30 Minuten (wie ich es gerne hätte).

Ich habe das Problem jetzt erstmal so gelöst, dass ich einfach beim deaktivieren die Maus vom Programm bewegen lasse und damit den Energiespartimer entsprechend zurücksetze. Zugegeben nicht die eleganteste Lösung... Und auf dieses Zurücksetzen des Timers zielte meine Frage.


Grüße


Holger

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt


Zuletzt bearbeitet von HolgerMaune am Do 22.03.07 09:32, insgesamt 1-mal bearbeitet
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 21.03.07 23:49 
Titel: Festplatten zum Schlafen schicken
Festplatten zum Schlafen schicken kann man natürlich auch (nicht USB etc.):

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:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
var
  Form1: TForm1;

Type  
TIDERegs = packed record 
    bFeaturesReg     : Byte; // Used for specifying SMART "commands". 
    bSectorCountReg  : Byte; // IDE sector count register 
    bSectorNumberReg : Byte; // IDE sector number register 
    bCylLowReg       : Byte; // IDE low order cylinder value 
    bCylHighReg      : Byte; // IDE high order cylinder value 
    bDriveHeadReg    : Byte; // IDE drive/head register 
    bCommandReg      : Byte; // Actual IDE command. 
    bReserved        : Byte; // reserved for future use.  Must be zero. 
  end
  IDEREGS   = TIDERegs; 
  PIDERegs  = ^TIDERegs; 

TIdSector = packed record 
    wGenConfig                 : Word; //00 
    wNumCyls                   : Word; 
    wReserved                  : Word; 
    wNumHeads                  : Word; 
    wBytesPerTrack             : Word; 
    wBytesPerSector            : Word; 
    wSectorsPerTrack           : Word; 
    wVendorUnique              : Array[0..2of Word; 
    sSerialNumber              : Array[0..19of Char; //10-19 
    wBufferType                : Word; 
    wBufferSize                : Word; 
    wECCSize                   : Word; 
    sFirmwareRev               : Array[0..7of Char;  //23-26 
    sModelNumber               : Array[0..39of Char; //27-46 
    wMoreVendorUnique          : Word; 
    wDoubleWordIO              : Word; 
    wCapabilities              : Word; 
    wReserved1                 : Word; 
    wPIOTiming                 : Word; 
    wDMATiming                 : Word; 
    wBS                        : Word; 
    wNumCurrentCyls            : Word; 
    wNumCurrentHeads           : Word; 
    wNumCurrentSectorsPerTrack : Word; 
    ulCurrentSectorCapacity    : ULONG; //57-58 
    wMultSectorStuff           : Word; 
    ulTotalAddressableSectors  : ULONG; //60-61 
    wSingleWordDMA             : Word; 
    wMultiWordDMA              : Word;  //63 
    wFlowControlPIOSupported   : Word;  //64 
    wMinimumMultiWordDMA       : Word;  //65 
    wRecommendedMultiWordDMA   : Word;  //66 
    wMinimumPIOCycleWOFlow     : Word;  //67 
    wMinimumPIOCycleIORDYFlow  : Word;  //68 
    bReserved1                 : Array[0..21of Byte; //69-79 
    wMajorVersionNumber        : Word;  //80 
    wMinorVersionNumber        : Word;  //81 
    wCommandSetSupported       : Word;  //82 
    wCommandSetSupported2      : Word;  //83 
    wCommandSetExtension       : Word;  //84 
    wCommandSetFeatureEnabled1 : Word;  //85 
    wCommandSetFeatureEnabled2 : Word;  //86 
    wCommandSetFeatureEnabled3 : Word;  //87 
    wUltraDMAMode              : Word;  //88 
    wTimeRequiredErase         : Word;  //89 
    wTimeRequiredEnhancedErase : Word;  //90 
    wAbleMode                  : Word;  //91 
    bReserved2                 : Array[0..71of Byte; //92-127 
    wSecurityModeFeature       : Word;  //128 
    wCurrentFeatureOption      : Word;  //129 
    wReserved2                 : Word;  //130 
    wInitialPowerMode          : Word;  //131 
    bReserved3                 : Array[0..247of Byte; //132-255 
  end
  PIdSector = ^TIdSector;

 const 
  BufferSize = SizeOf(TIDERegs)+4
  IOCTL_IDE_PASS_THROUGH        = $0004d028;


implementation

{$R *.dfm}

Function IdeRegPassThrough(Device: Stringvar ideregs: TIDERegs ): Boolean; 
var 
  ret:BOOL; 
  hDevice : THandle; 
  cbBytesReturned : DWORD; 
  pInData : PIDERegs; 
  pOutData : Pointer; 
  Buffer : Array[0..BufferSize-1of Byte; 
begin 
  Result := False; 
  FillChar(Buffer,BufferSize,#0); 

  hDevice := CreateFile( PChar(Device), GENERIC_READ or GENERIC_WRITE, 
    FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 00 ); 
  if hDevice=INVALID_HANDLE_VALUE then Exit; 
  try 
    pInData := @Buffer; 
     pOutData := pInData; 
    pInData^ := ideregs; 
    ret := DeviceIoControl( hDevice, IOCTL_IDE_PASS_THROUGH, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ); 
    if not ret then begin 
      Exit; 
    end
    ideregs := PIDERegs(pOutData)^; 
  finally 
    CloseHandle(hDevice); 
  end
  Result := True; 
end

function SendToSleep(Device: String): Boolean;
var 
  ideregs : TIDERegs; 
begin 
  Result := False; 
  with ideregs do 
  begin 
    bFeaturesReg     := 0
    bSectorCountReg  := 0
    bSectorNumberReg := 0
    bCylLowReg       := 0
    bCylHighReg      := 0
    bDriveHeadReg    := $A0
    bCommandReg      := $E6
    bReserved        := 0
  end
  if not IdeRegPassThrough(Device, ideregs ) then Exit else Result := True; 
end;
// If SendToSleep('\\.\PhysicalDrive0'))= true then...;
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Do 22.03.07 10:16 
HolgerMaune hat folgendes geschrieben:
[..] wird die var <aktiv> auf false gesetzt. Dies hatte zur Folge, dass der Bildschirm sofort eingeschlafen ist und nicht erst nach 30 Minuten (wie ich es gerne hätte).

Definier' doch noch eine weitere Bedingung zusätzlich zu

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  if ((Msg.CmdType = SC_MONITORPOWER) or (Msg.CmdType = SC_SCREENSAVE)) and not aktiv then 
  begin 
    Msg.Result := -1
  end


evtl. kombiniert mit einem Timer.


@hathor

Deine Antwort schießt zwar irgendwie an Holgers Frage vorbei, aber der Code ist für mich interessant.
Übergebe ich hier einfach den String z.B. 'C:' oder 'D:'? Und funktioniert der Code auch für die Systemfestplatte? Wenn ja, was passiert dann?
ausblenden Delphi-Quelltext
1:
function SendToSleep(Device: String): Boolean;					


Gruß

Calculon
--
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 22.03.07 11:27 
user profile iconCalculon hat folgendes geschrieben:
Hi Leute!

Geht es irgendwie mit Delphi die Energieoptionen (Monitor ausschalten, Festplatten ausschalten, Standby, Ruhezustand) vorübergehend zu deaktivieren? Wichtig ist mir v.a. Monitor ausschalten, da die anderen bei mir sowieso deaktiviert sind.

Gruß

Calculon
--


1. Meine Antwort bezieht sich auf DEINE Frage - schon vergessen???
Zugegeben, man muss ein bisschen um die Ecke denken:
Es gibt nur 1 Energieschema, das die Festplatten in der Voreinstellung abschaltet (Notebook), manuell kann man es natürlich überall eintragen - andererseits: wenn man die Festplatten NICHT im gewählten Energieschema ausschalten lassen will, kann man in eigenen Programmen die SendToSleep-Funktion verwenden...

2. Wie man die Funktion SendToSleep anwendet, steht in der letzten Zeile.

3. Bei einem HDD-Zugriff wacht sie wieder auf.

Es funtioniert nur bei HDD, bei denen das Interface die S.M.A.R.T.-Befehle weiterleitet.

NACHTRAG: Habe das hier noch gefunden:

www.delphipraxis.net...tte+ausschalten.html


Zuletzt bearbeitet von hathor am Do 22.03.07 12:05, insgesamt 2-mal bearbeitet
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Do 22.03.07 11:40 
:idea: Achja, ist ja mein Thread :oops:

Funktioniert super, muss noch'n bißchen damit rumspielen;

Gruß

Calculon
--