Solved

Shutdown windows

Posted on 1998-12-10
2
210 Views
Last Modified: 2012-05-04
How do I force windows to shutdown / reboot?
0
Comment
Question by:qwertyx
2 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1350290
hi qwertyx,

look at this free component with source

http://www.torry.webnorth.com/vcl/system/wreboot.zip

meikl
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 30 total points
ID: 1350291
see http://www.chami.com/tips/delphi/120996D.html or write the following code:

Var
 PreviosPrivileges: ^TTokenPrivileges;
 TokenPrivileges: TTokenPrivileges;
 ProcessHandle: THandle;
 tmp: Integer;
begin
if not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,ProcessHandle)   then Exit;
   LookupPrivilegeValue('', 'SeShutdownPrivilege', TokenPrivileges.Privileges[0].Luid);
   TokenPrivileges.PrivilegeCount:=1;
   TokenPrivileges.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
   tmp:=0;
   PreviosPrivileges:=nil;
   AdjustTokenPrivileges(ProcessHandle, False, TokenPrivileges, 0,    PreviosPrivileges^ ,tmp);
   if not GetLastError()=ERROR_SUCCESS then Exit;
   if not InitiateSystemShutdown('', '', 0, True, True) then Exit;
   TokenPrivileges.Privileges[0].Attributes:=0;
   AdjustTokenPrivileges(ProcessHandle, False, TokenPrivileges,    0,PreviosPrivileges^ ,tmp);
End;
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

11 Experts available now in Live!

Get 1:1 Help Now