Solved

HOW TURN OFF WINDOWS XP

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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