Solved

How to shut down computer

Posted on 2002-04-09
4
318 Views
Last Modified: 2010-04-04
I am using win 98. In my program, I want to have a shutting down computer function. I try to use ExitWindowsEx(EWX_POWEROFF, 0). But it only does log off in win 98, win me and do nothing in win 2000.
So how can the program shut down a computer?

Thank u


Peter
0
Comment
Question by:petershaw9
4 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 6927820
Hi,
Use EWX_SHUTDOWN instead. Or (EWX_FORCE or EWX_SHUTDOWN,0) to close all apps immediately.

Regards, Geo
0
 
LVL 1

Accepted Solution

by:
TAZI earned 200 total points
ID: 6927827
Hi ..

Herewith, a piece of code that may assist.

function MyExitWindows(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;




procedure TForm1.Button1Click(Sender: TObject);
begin
  MyExitWindows(EWX_SHUTDOWN);
end;


Hope this helps

Regards
TAZI
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6927853
'Shutdown PC with all Windows versions' article at http://www.delphi3000.com/article.asp?ID=2108
0
 
LVL 15

Expert Comment

by:simonet
ID: 6928010
Here's an article I wrote about this very same issue:


http://www.bhnet.com.br/~simonet/tipstricks/exitwindowsnt.htm

Yours,

Alex
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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