Solved

Force Reboot system

Posted on 2002-04-27
8
245 Views
Last Modified: 2010-04-04
HOw can i FORCE REBOOT or RESTART WINDOWS XP.
Im making an Installer and i want to reboot the system, WINDOWS XP, please help!
0
Comment
Question by:girlswants_me
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:girlswants_me
ID: 6974535
help me please
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6974585
Var tkp: TTokenPrivileges;
    hToken : THandle;

if not OpenProcessToken( GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken) then
  raise Exception.Create( 'Error when opening the process token');
LookupPrivilegeValue( nil,
                      'SeShutdownPrivilege',
                      tkp.Privileges[0].Luid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken, False, tkp, 0, nil, l);
ExitWindowsEx( EWX_SHUTDOWN, 0);  
0
 
LVL 2

Accepted Solution

by:
Tasomia earned 50 total points
ID: 6974588
function MyExitWindows(RebootParam: LongWord): Boolean;
var
  TTokenHd: THandle;
  TTokenPvg: TTokenPrivileges;
  cbtpPrevious: DWORD;
  rTTokenPvg: TTokenPrivileges;
  pcbtpPreviousRequired: DWORD;
  tpResult: Boolean;
const
  SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
    tpResult := OpenProcessToken(GetCurrentProcess(),
      TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
      TTokenHd);
    if tpResult then
    begin
      tpResult := LookupPrivilegeValue(nil,
                                       SE_SHUTDOWN_NAME,
                                       TTokenPvg.Privileges[0].Luid);
      TTokenPvg.PrivilegeCount := 1;
      TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      cbtpPrevious := SizeOf(rTTokenPvg);
      pcbtpPreviousRequired := 0;
      if tpResult then
        Windows.AdjustTokenPrivileges(TTokenHd,
                                      False,
                                      TTokenPvg,
                                      cbtpPrevious,
                                      rTTokenPvg,
                                      pcbtpPreviousRequired);
    end;
  end;
  Result := ExitWindowsEx(RebootParam, 0);
end;


// Example

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyExitWindows(EWX_REBOOT or EWX_FORCEIFHUNG );
end;
0
Industry Leaders: 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!

 
LVL 9

Expert Comment

by:ginsonic
ID: 6974595
I forgot to add:
var l:dword;

and replace

ExitWindowsEx( EWX_SHUTDOWN, 0);  
with
ExitWindowsEx( EWX_REBOOT, 0);

I tested just after what I put my comment .
0
 

Author Comment

by:girlswants_me
ID: 6974661
This answers cant REBOOT my WINDOWS XP operating System.
have you everybody try it in WINDOWS XP?
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6974708
>have you everybody try it in WINDOWS XP?

I tested it on XP and this works:

MyExitWindows(EWX_REBOOT or EWX_FORCE);
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6974855
I tested my version on XP Pro and work fine .
0
 

Author Comment

by:girlswants_me
ID: 6976468
thanks for the help
0

Featured Post

Industry Leaders: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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