Smallest code ever to reboot on all PCs

Share your advanced PureBasic knowledge/code with the community.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Smallest code ever to reboot on all PCs

Post by PB »

I know this is just a dirty hack, and I would never actually use it in a full
release app, but it seems to be the smallest code ever to reboot a PC on
all versions of Windows. :)

Edit: Modified to run on ANY language version of Windows now.
Works on Windows 95, 98, ME, 2000 and XP (tested fine on all).

Code: Select all

; WARNING: YOUR PC WILL REBOOT IF YOU RUN THIS CODE!

Procedure Reboot()
  fg=GetForegroundWindow_()
  Repeat : Sleep_(1) : Until GetForegroundWindow_()<>fg
  keybd_event_(#VK_RETURN,0,0,0)
EndProcedure

CreateThread(@Reboot(),0)
SetupPromptReboot_(0,0,0)
Last edited by PB on Fri Dec 22, 2006 11:40 pm, edited 1 time in total.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

You mean apart from...

Code: Select all

MessageRequester("", "Press reset now")
repeat: forever
:P :twisted:
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post by Seldon »

Sorry, but what's wrong with this code ? ->

ExitWindowsEx_(#EWX_FORCE|#EWX_REBOOT,0)

As I'm using it on Win98SE and it works.. maybe are there problems on NT/2000/XP ?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Seldon wrote:Sorry, but what's wrong with this code ? ->

ExitWindowsEx_(#EWX_FORCE|#EWX_REBOOT,0)

As I'm using it on Win98SE and it works.. maybe are there problems on NT/2000/XP ?
Your program needs certain security permissions to reboot the system under NT based versions of Windows. I dunno if this is just a case of running it as a user with enough security, or perhaps your program can ask for it.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Berikco
Administrator
Administrator
Posts: 1328
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

tinman wrote:
Seldon wrote:Sorry, but what's wrong with this code ? ->

ExitWindowsEx_(#EWX_FORCE|#EWX_REBOOT,0)

As I'm using it on Win98SE and it works.. maybe are there problems on NT/2000/XP ?
Your program needs certain security permissions to reboot the system under NT based versions of Windows. I dunno if this is just a case of running it as a user with enough security, or perhaps your program can ask for it.
It will not work on NT/w2k/Xp/2003 , not even if you are loged on as administrator.

The complete code to use ExitWindowsEx_() on NT/.... has been posted a couple of times.
Berikco
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> ExitWindowsEx_(#EWX_FORCE|#EWX_REBOOT,0)
> I'm using it on Win98SE and it works.. maybe are there problems on
> NT/2000/XP ?

Correct, it won't work on NT/2K/XP. My tip does, though. However, my
tip is not something you'd actually use, as it depends on the language of
the OS installed and so on -- and is just a hack method anyway. I found
the SetupPromptReboot API from the API-Guide app (sorry, no URL) and
decided to see if I could force a reboot with it, and I could -- so I posted
it here as an example. :)
Berikco
Administrator
Administrator
Posts: 1328
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Yes, small code, but ist going to get bloated if you must include for all languages ;)
Berikco
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Yes, small code, but ist going to get bloated if you must include for all languages ;)

LOL, that's very true! :)
Post Reply