Solved

HOW TURN OFF WINDOWS XP

Posted on 2004-04-18
5
485 Views
Last Modified: 2010-04-05
hi
if i want turn off system with code of my delphi
in windows xp i con not run this statement  ExitWindowsex
i just log off
tank you for next help

0
Comment
Question by:HOSIN_SHAFIEI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10857386
have you tried  ExitWindowsEx(EWX_POWEROFF ,0);  ?

from microsoft;
******************************
uFlags
     One or more of the following flags specifying how to shut down or reboot the computer:
     EWX_FORCE = 4
          Force any applications to quit instead of prompting the user to close them.
     EWX_LOGOFF = 0
          Log off the network.
     EWX_POWEROFF = 8
          Shut down the system and, if possible, turn the computer off.
     EWX_REBOOT = 2
          Perform a full reboot of the system.
     EWX_SHUTDOWN = 1
          Shut down the system.
dwReserved
     Reserved for future versions of Windows. Always set to 0.
******************************

0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10857394
BTW If it don't work anymore look at this Madshi PAQ that have explained and solved this matter on XP Systems...

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20268837.html
0
 
LVL 11

Expert Comment

by:calinutz
ID: 10857616
Try this

function ExitWindows(RebootParam: Longword): Boolean;
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
tpResult: Boolean;
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
  tpResult := OpenProcessToken(GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
    TTokenHd);
  if tpResult then
  begin
    tpResult := LookupPrivilegeValue(nil,
                                     SE_SHUTDOWN_NAME,
                                     TTokenPvg.Privileges[0].Luid);
    TTokenPvg.PrivilegeCount := 1;
    TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    cbtpPrevious := SizeOf(rTTokenPvg);
    pcbtpPreviousRequired := 0;
    if tpResult then
      Windows.AdjustTokenPrivileges(TTokenHd,
                                    False,
                                    TTokenPvg,
                                    cbtpPrevious,
                                    rTTokenPvg,
                                    pcbtpPreviousRequired);
  end;
end;
Result := ExitWindowsEx(RebootParam, 0);
end;


//And call it like this

procedure TForm1.Button1Click(Sender: TObject);
begin
ExitWindows(EWX_POWEROFF or EWX_SHUTDOWN);
end;
0
 

Accepted Solution

by:
lopardo2003 earned 50 total points
ID: 10865151
Check this demo about how to shutdown / restart / hibernate / standby / log off / turn off screen in any Windows version:
http://360software.dakotabcn.net/files/systemactions.zip
0
 

Author Comment

by:HOSIN_SHAFIEI
ID: 10866434
hi
 thank of all teachers
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question