Solved

Shutdown windows

Posted on 1998-12-10
2
213 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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 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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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