Solved

HOW TURN OFF WINDOWS XP

Posted on 2004-04-18
5
481 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now