[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

HOW TURN OFF WINDOWS XP

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
HOSIN_SHAFIEI
Asked:
HOSIN_SHAFIEI
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
calinutzCommented:
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
 
lopardo2003Commented:
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
 
HOSIN_SHAFIEIAuthor Commented:
hi
 thank of all teachers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now