Solved

Shutdown windows

Posted on 1998-12-10
2
218 Views
Last Modified: 2012-05-04
How do I force windows to shutdown / reboot?
0
Comment
Question by:qwertyx
[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
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

Technology Partners: 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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

628 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