Solved

Force Reboot system

Posted on 2002-04-27
8
246 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
[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
  • 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
Independent Software Vendors: 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

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

733 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