Solved

Shutdown windows

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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