Reboot?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by scurrier.

How do i reboot the computer from within my code?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by scurrier.

I found out how to logoff use this:
ExitWindowsEx_(0,1)
does anyone know how to reboot?

thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

From the Win help file:

ExitWindowsEx(uFlags,dwReserved)
uFlags = UINT // shutdown operation
dwReserved = DWORD // reserved, this parameter is ignored

uFlags can be:
EWX_FORCE
EWX_LOGOFF
EWX_POWEROFF
EWX_REBOOT
EWX_SHUTDOWN

reboot should be:
ExitWindowsEx_(#EWX_REBOOT,0) ;not tested yet



Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Stan.

Hi,
How do i reboot the computer from within my code?
Plz take no offence, why do you need to do that ? (I'm just curious).

Bests.

Stan


Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by scurrier.

because i wrote a program that updates an ini file then i need the computer to reboot so it loads the new ini file

Thanks
Sean
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by scurrier.

I tried your code but it didn't work

thanks anyways
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

why do you not only read the ini file again??? I hate applikations who need a complete reboot instead of a restart of a application. Seems curious.

Mike

Tranquilizer/ Secretly!
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by scurrier.

Ok I need a way to kill the app then.
the ini file that i am changeing belongs to anouther app
and i have no way restarting the app within my program
if you can tell me how to do that i won't use the reboot

thanks
Sean
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.
Ok I need a way to kill the app then.
if you can tell me how to do that i won't use the reboot
You could always get the handle of the other window then post a close message to it... here is a quick example:

hWnd=FindWindow_(0,"Untitled - Notepad")
PostMessage_(hWnd,16,0,0)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
I tried your code but it didn't work
Tested on Win98SE (@work) and it works fine.
Sometimes the shutdown/reboot process is disturbed be some 'intelligent' application and you have to start your reboot routine twice...


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by scurrier.

Thanks i will try this.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.

In NT/W2K/XP you need to set some security token to reboot.
I have writen this once in GFA Basic 32....converted quickly to PB...but does not work (just using PB one week now)

Can anybody with more PB expirience take a look at this

#SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
#SE_PRIVILEGE_ENABLED = 2
#TOKEN_ADJUST_PRIVILEGES = 32
#TOKEN_QUERY = 8

Structure LUID
lowpart.l
highpart.l
EndStructure

Structure LUID_AND_ATTRIBUTES
pLuid.LUID
Attributes.l
EndStructure

Structure TOKEN_PRIVILEGES
PrivilegeCount.l
Privileges0.LUID_AND_ATTRIBUTES
Privileges1.LUID_AND_ATTRIBUTES
EndStructure

DefType.l token
Dim privilege.LUID(1)
Dim TP.TOKEN_PRIVILEGES(1)
Dim TP2.TOKEN_PRIVILEGES(1)
DefType.l process

process = GetCurrentProcess_()

If OpenProcessToken_(process, #TOKEN_ADJUST_PRIVILEGES Or #TOKEN_QUERY, token)
If LookupPrivilegeValue_("", #SE_SHUTDOWN_NAME, privilege)
TP(0)\PrivilegeCount = 1
TP(0)\Privileges0\Attributes = #SE_PRIVILEGE_ENABLED
TP(0)\Privileges0\pLuid = privilege
AdjustTokenPrivileges_(token, False, TP, 4 + (12 * TP(0)\PrivilegeCount), TP2, 4 + (12 * TP2(0)\PrivilegeCount))
ExitWindowsEx_( #EWX_FORCE | #EWX_REBOOT, 0)

TP(0)\PrivilegeCount = 1
TP(0)\Privileges0\Attributes = 0
TP(0)\Privileges0\pLuid = privilege
AdjustTokenPrivileges_(token, False, TP, 4 + (12 * TP(0)\PrivilegeCount), TP2, 4 + (12 * TP2(0)\PrivilegeCount))
EndIf
EndIf



Edited by - benny Sels on 16 June 2002 21:58:11

Edited by - benny Sels on 16 June 2002 22:00:35
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Schlowski.

Some weeks ago I needed such a little rebooter, so here are the sources:

Code: Select all

 #TOKEN_ADJUST_PRIVILEGES = 32
#TOKEN_QUERY = 8
#SE_PRIVILEGE_ENABLED = 2
#EWX_LOGOFF = 0
#EWX_SHUTDOWN = 1
#EWX_REBOOT = 2
#EWX_FORCE = 4
#EWX_POWEROFF = 8

Structure MyLUID
   LowPart.l
   HighPart.l
   Attributes.l
EndStructure

Structure MyTOKEN
   PrivilegeCount.l
   LowPart.l
   HighPart.l
   Attributes.l
EndStructure

Global hdlProcessHandle.l
Global hdlTokenHandle.l
Global tmpLuid.MyLUID
Global tkp.MyTOKEN
Global tkpNewButIgnored.MyTOKEN
Global lBufferNeeded.l

hdlProcessHandle = GetCurrentProcess_()
    
OpenProcessToken_(hdlProcessHandle, #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)

; Get the LUID For shutdown privilege.
SysName.s=""+Chr(0)
Name.s="SeShutdownPrivilege"+Chr(0)
Erg.l=LookupPrivilegeValue_(SysName, Name, @tmpLuid)

tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
tkp\PrivilegeCount = 1  
tkp\LowPart = tmpLuid\LowPart
tkp\HighPart = tmpLuid\HighPart
tkp\Attributes = tmpLuid\Attributes

; Enable the shutdown privilege in the access token of this process.
Erg.l = AdjustTokenPrivileges_(hdlTokenHandle,0,@tkp,SizeOf(MyTOKEN),@tkpNewButIgnored,@lBufferNeeded)
Erg.l = ExitWindowsEx_((#EWX_SHUTDOWN | #EWX_POWEROFF | #EWX_FORCE), 0)
If Erg=0 
   OpenConsole()
   Buffer.s = Space(200)
   FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), #LANG_NEUTRAL, @Buffer, 200, 0)
   PrintN(Buffer)
   Input()
   CloseConsole()
EndIf   
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Hi Schlowski ...

This last code works fine on my W2K.

Just it works only as an executable but not from PB editor, which is probably because of 'user rights'.

Executing the compiled program works.

Francois Weil
14, rue Douer
F64100 Bayonne
Post Reply