Link to home
Start Free TrialLog in
Avatar of A. Cristian Csiki
A. Cristian CsikiFlag for Ireland

asked on

Reset computer

Greetings.
I'm wondering if there is a way to make a system reset from a source code? Any ideas how ?
Thanks for caring.
Avatar of TName
TName

Do you mean restart the OS, like in

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExitWindowsEx(EWX_REBOOT,0);
end;

or am I way off target?
Yeah I think that is what he wants

to reboot;

exitwindowsex(EWX_REBOOT,0);

to shutdown

exitwindowsex(EWX_SHUTDOWN,0); (or with ewx_poweroff)
Avatar of A. Cristian Csiki

ASKER

I now to reboot the system, but I want to reset it. Like the reset button does. Is this posible?
But that is what the reset button does .. it reboots the PC .. or have I been told a lie for the last 20 years he he
I think the idea is to reboot without cleanly shutting down. If  yes, then it would't be a very nice thing to do by code, I think. You only use the reset button when the OS is non-responsive, in which case your application should be pretty much helpless also...
ok, my mistake :D. But still the code doesn't work. I have win xp sp 2 and doesn't do nothing. :(
ASKER CERTIFIED SOLUTION
Avatar of TName
TName

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But save your project first :)
Or better: don't do it with the IDE running!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just my 2 cents...

If you really really want to do a hardware reset, most motherboards have two pins on one of the header connectors that when shorted will do a hardware reset. It brings all the reset lines on the buses to logic 0 and will do a hardware reset.

To do this you must of course short those pins or at least bring the active reset pin to ground. The reset pin will normally be at about +5 volts.

This can be accomplished by a single PNP transistor, a 1.2K Ohm resistor and some port software and a port driver for Win NT and above.

Basically, you could connect the base of the transistor to one of the data lines of an unused parallel/printer port, the emitter and collector properly connected between the reset pin and ground, use the port driver and software to bring that pin low which will in turn cause the the transistor to conduct and pow, your PC will reset.

A lot to do for a hardware reset, but it works. There are a lot of circuits out there for using your printer port for control and JDR Microdevices in California has  complete PCI and ISA board for output control. There are freeware drivers for direct access to ports as well.

This verbal example is overly simplified, and right now I am not certain if you would need a PNP or NPN transistor, but hopefully you get the point.

Also, hardware resets can cause problems with your hard drives and data especially if doing a write at the time of the reset.

John
Hello Sir,

   Place a button on the form and use the following procedure to shutdown windows. Kindly check the various other options under ExitWindowsEx function available under Windows SDK.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure ExitWin2000(ewx: integer);
var
 hToken: THANDLE;
 hProc: THANDLE;
 mLUID: TLargeInteger;
 mPriv, mNewPriv: TOKEN_PRIVILEGES;
 mBufferLength: DWord;
begin
 if not (ewx in [1, 2]) then
   exit;
 hProc := GetCurrentProcess();
 OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken);
 LookupPrivilegeValue('', 'SeShutdownPrivilege', mLUID);
 mPriv.PrivilegeCount := 1;
 mPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
 mPriv.Privileges[0].Luid := mLUID;
 AdjustTokenPrivileges(hToken, False, mPriv, (4 + (12 * mPriv.PrivilegeCount)), mNewPriv, mBufferLength);
 case ewx of
   1: ExitWindowsEx(EWX_FORCE + EWX_REBOOT, 0);
   2: ExitWindowsEx(EWX_FORCE + EWX_POWEROFF, 0);
 end;
end;
procedure shutDown();
var
 os:OSVERSIONINFO;
begin
 os.dwOSVersionInfoSize:=sizeOf(TOSversionInfo);
 getVersionEx(os);
 if (os.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS) then
   exitWindowsEx(EWX_SHUTDOWN,0);
 if (os.dwPlatformId=VER_PLATFORM_WIN32_NT) then
   exitWin2000(2);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShutDown;
end;

end.

with regards,
padmaja.
i'll split the points between TNAME and rllibby because they had the closest answers to my q. Thanks to all.