Autor Beitrag
Unknown
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Mo 06.11.06 16:01 
Hallo,
Ich wollte wissen ob man durch delphi den PC sinngemäß herunterfahren kann.
Wenn ja wie(am besten mit Quelltext).
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Mo 06.11.06 19:49 
Ja, kann man! Und vor allem kann man auch mal die Suche benutzen!

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
Unknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Mi 08.11.06 14:33 
HAHA Witzig....
Da hab ich schon gesucht und nur so etwas gefunden:
Exitwindowex(EWX_Shutdown or EWX_POWEROFF, §FFFFFFFF)
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 08.11.06 14:46 
user profile iconUnknown hat folgendes geschrieben:
HAHA Witzig....
Da hab ich schon gesucht und nur so etwas gefunden:
Exitwindowex(EWX_Shutdown or EWX_POWEROFF, §FFFFFFFF)

Ja und? Was stimmt damit nicht?
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Mi 08.11.06 15:23 
www.delphi-library.d...neustarten_8272.html
Um Tino mal die Worte aus dem Mund zu nehmen:
Hier mal ein paar Beispiel wie ExitWindowsEx aufgerufen werden kann:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// Windows runterfahren
ExitWindowsEx (EWX_SHUTDOWN, $FFFFFFFF);
// Windows runterfahren und Computer ausschalten
ExitWindowsEx (EWX_SHUTDOWN or EWX_POWEROFF, $FFFFFFFF);
// Windows neustarten
ExitWindowsEx (EWX_REBOOT, $FFFFFFFF);
// Benutzer abmelden
ExitWindowsEx (EWX_LOGOFF, $FFFFFFFF);


ich weiß jetzt nicht, wo genau das problem liegt, besser kann man code net posten!

:r:

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 08.11.06 15:36 
Das Problem wird sein, dass man unter NT ff. erst das Privileg zum Runterfahren aktivieren muss. Aber das wird in jedem Posting, dass man mit ExitWindowsEx findet erwähnt und erklärt. :roll:
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Mi 08.11.06 15:47 
Tja, das wird er aber nur sehen, wenn er sich den Thread richtig durchliest.. Zumal darauf im geposteten Thread eingegangen wird ;)
Naja, er wirds schon machen.

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
Unknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Mi 08.11.06 16:35 
Nein,nein...
Ich hab mir den Thread schon durchgelesen 8)
Und dann hab ich das gemacht
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Procedure Button1Click (...)
begin
  ExitWindowEx(EWX_Shutdown or EWX_POWEROFF, §FFFFFFFF)
end;

Mehr hab da nich t hingeschrieben.
muss ich da noch noch bei uses windows hinschreiben??
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 08.11.06 16:38 
user profile iconUnknown hat folgendes geschrieben:
Nein,nein...
Ich hab mir den Thread schon durchgelesen 8)

Anscheinend aber nicht alles. Zu dem habe ich auch geschrieben, was du noch machen musst. Und das wird auch in jedem Thread erklärt.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 08.11.06 16:49 
Für den Fall, dass es compiliert, aber nicht funktioniert: Den verlinkten Thread nochmal lesen. Ganz besonders den Teil über Windows NT (und WindowsXP ist auch ein NT-System!).
Für den Fall, dass es nicht compiliert: Unit ShellApi einbinden.

_________________
We are, we were and will not be.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 08.11.06 16:52 
Ich glaub ja, dass das ein Tippfehler im Forum ist, aber er kam jetzt schon zweimal vor, daher die Frage: Du weißt, dass man Hex-Zahlen mit einem Dollar- und nicht mit einem Paragraphen-Zeichen einleitet?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Mi 08.11.06 18:00 
Aber wenn er den Code per copy n paste einfügt, sollte er $ und & net verwechseln können.
Derjenige, der geposteten Code abtippt, der werfe den ersten Stein ;)

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
Unknown Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 184

Win XP
Delphi 7
BeitragVerfasst: Do 09.11.06 14:31 
Ok danke funzt alles...
Wusste nicht das XP zu NT gehört :oops: :oops:
Na klar, es heißt $ und nicht §
angel324
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 13.11.06 23:54 
Hallo,
ich habe auch ein kleines Problem beim Herunterfahren mit Windows.
Ich habe den Code von www.delphi-library.d...hlight=exitwindowsex

Der Code funktioniert ja auch, aber nur wenn ich mein Programm unter Delphi starte (F9).
Starte ich mein Programm mit eine Doppelklick auf die Datein unter Windows passiert bei dem gleichen Button gar nix.

Wo kann der Felher sein??
Der Code so bei mir unter W2k SP4 und WinXP SP2 funzen.

ausblenden volle Höhe Windows herunterfahren
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, Buttons, Registry, ShellAPI;

type
TShutdownWindowsType = (swtShutdown, swtShutdownPowerOff, swtRestart, swtLogoff);
  TForm1 = class(TForm)
    Herunterfahren: TButton;
    Neustarten: TButton;
    Ausloggen: TButton;
    procedure HerunterfahrenClick(Sender: TObject);
    procedure NeustartenClick(Sender: TObject);
    procedure AusloggenClick(Sender: TObject);
  private
   { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function ShutdownWindows (aType: TShutdownWindowsType): Boolean;

const
  cSE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
  cFlagValue: Array [TShutdownWindowsType] Of UINT = (
      EWX_SHUTDOWN, EWX_SHUTDOWN or EWX_POWEROFF or EWX_FORCEIFHUNG, EWX_REBOOT, EWX_LOGOFF
    );

var
  OSVersionInfo: TOSVersionInfo;
  hToken: THandle;
  hProcess: THandle;
  TokenPriv: TTokenPrivileges;
  ReturnLength: DWORD;

begin
  Result := False;

  // Die Windowsversion holen
  OSVersionInfo.dwOSVersionInfoSize := SizeOf (OSVersionInfo);
  if not GetVersionEx (OSVersionInfo) then
    Exit;

  // Prüfen ob Windows NT
  if OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
    begin
      hProcess := GetCurrentProcess;
      if not OpenProcessToken (hProcess, TOKEN_ADJUST_PRIVILEGES, hToken) then
        Exit;

      if not LookupPrivilegeValue (nil, cSE_SHUTDOWN_NAME, TokenPriv.Privileges[0].Luid) then
        Exit;

      TokenPriv.PrivilegeCount := 1;
      TokenPriv.Privileges [0].Attributes := SE_PRIVILEGE_ENABLED;

      if not AdjustTokenPrivileges (
          hToken, False, TokenPriv, 0,
          PTokenPrivileges (nil)^, ReturnLength
        )
      then
        Exit;

      CloseHandle (hToken);
    end;

  ShutdownWindows := ExitWindowsEx (cFlagValue [aType], $FFFFFFFF);
end;                                                                    


procedure TForm1.NeustartenClick(Sender: TObject);                        
begin                                                                     
 ShutdownWindows(swtRestart);//Neustart                                   
end;

procedure TForm1.AusloggenClick(Sender: TObject);                         
begin                                                                     
 ShutdownWindows(swtLogoff); //Ausloggen                       
end;                                                                      

procedure TForm1.HerunterfahrenClick(Sender: TObject);                    
begin                                                                     
 ShutdownWindows(swtShutdownPowerOff);//Beenden (ATX)                             
end;



Ich danke euch für euere Hilfe...

Gruß

Mathias