?
Solved

Force Reboot system

Posted on 2002-04-27
8
Medium Priority
?
250 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 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