Solved

About System's Question

Posted on 2002-07-04
6
188 Views
Last Modified: 2010-04-04
Help,Help!!!
How to Shut Down my PC in WIN2000?
Wait for your answer
0
Comment
Question by:Aquadp
[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
6 Comments
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7130949
unit ShutDown;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  rl: Cardinal;
  hToken: Cardinal;
  tkp: TOKEN_PRIVILEGES;

begin
  if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
  hToken) then
    ShowMessage('Cannot open process token.')
  else begin
    if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin
      tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      tkp.PrivilegeCount           := 1;
      AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
      if GetLastError <> ERROR_SUCCESS then
        ShowMessage('Error adjusting process privileges.');
    end
    else
      ShowMessage('Cannot find privilege value.');
  end;

  InitiateSystemShutdown(nil, nil, 10, True, True);

end;

end.


The Crazy One
0
 

Author Comment

by:Aquadp
ID: 7131190
thanks
I get it!
but the function InitiateSystemShutdown was rebooted my PC.
0
 
LVL 44

Accepted Solution

by:
CrazyOne earned 20 total points
ID: 7131213
Sorry it should be this to shutdown

InitiateSystemShutdown(nil, nil, 10, True, False);


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/shutdown_04ry.asp

Platform SDK: Windows System Information

"InitiateSystemShutdown
The InitiateSystemShutdown function initiates a shutdown and optional restart of the specified computer.

To record a reason for the shutdown in the event log, call the InitiateSystemShutdownEx function.

BOOL InitiateSystemShutdown(
  LPTSTR lpMachineName,      // computer name
  LPTSTR lpMessage,          // message to display
  DWORD dwTimeout,           // length of time to display
  BOOL bForceAppsClosed,     // force closed option
  BOOL bRebootAfterShutdown  // reboot option
);
Parameters
lpMachineName
[in] Pointer to the null-terminated string that specifies the network name of the computer to shut down. If lpMachineName is NULL or an empty string, the function shuts down the local computer.
lpMessage
[in] Pointer to a null-terminated string that specifies a message to display in the shutdown dialog box. This parameter can be NULL if no message is required.
Windows XP: This string is also stored as a comment in the event log entry.

dwTimeout
[in] Specifies the time (in seconds) that the shutdown dialog box should be displayed. While this dialog box is displayed, the shutdown can be stopped by the AbortSystemShutdown function.
If dwTimeout is not zero, InitiateSystemShutdown displays a dialog box on the specified computer. The dialog box displays the name of the user who called the function, displays the message specified by the lpMessage parameter, and prompts the user to log off. The dialog box beeps when it is created and remains on top of other windows in the system. The dialog box can be moved but not closed. A timer counts down the remaining time before a forced shutdown.

If dwTimeout is zero, the computer shuts down without displaying the dialog box, and the shutdown cannot be stopped by AbortSystemShutdown.

bForceAppsClosed
[in] Specifies whether applications with unsaved changes are to be forcibly closed. If this parameter is TRUE, such applications are closed. If this parameter is FALSE, a dialog box is displayed prompting the user to close the applications.
bRebootAfterShutdown
[in] Specifies whether the computer is to restart immediately after shutting down. If this parameter is TRUE, the computer is to restart. If this parameter is FALSE, the system flushes all caches to disk, clears the screen, and displays a message indicating that it is safe to power down.
Return Values
If the function succeeds, the return value is nonzero."
0
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!

 

Author Comment

by:Aquadp
ID: 7131329
I looked up the function InitiateSystemShutdown's help in delphi.Now i see.
thank u very much!
0
 

Expert Comment

by:CleanupPing
ID: 9343103
Aquadp:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9460175
Aquadp,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to CrazyOne http:#7131213

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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