Solved

About System's Question

Posted on 2002-07-04
6
183 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
6 Comments
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
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
Comment Utility
thanks
I get it!
but the function InitiateSystemShutdown was rebooted my PC.
0
 
LVL 44

Accepted Solution

by:
CrazyOne earned 20 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

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

Expert Comment

by:CleanupPing
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

763 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

15 Experts available now in Live!

Get 1:1 Help Now