Solved

Force Reboot system

Posted on 2002-04-27
8
241 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
Comment Utility
help me please
0
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
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
Comment Utility
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
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

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

Expert Comment

by:Tasomia
Comment Utility
>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
Comment Utility
I tested my version on XP Pro and work fine .
0
 

Author Comment

by:girlswants_me
Comment Utility
thanks for the help
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now