Page 1 of 1
Posted: Wed Jun 12, 2002 7:01 pm
by BackupUser
Restored from previous forum. Originally posted by scurrier.
How do i reboot the computer from within my code?
Posted: Wed Jun 12, 2002 7:22 pm
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
Posted: Wed Jun 12, 2002 7:38 pm
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.
Posted: Thu Jun 13, 2002 11:23 am
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 ]
Posted: Thu Jun 13, 2002 12:27 pm
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
Posted: Thu Jun 13, 2002 12:31 pm
by BackupUser
Restored from previous forum. Originally posted by scurrier.
I tried your code but it didn't work
thanks anyways
Posted: Thu Jun 13, 2002 12:52 pm
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
Posted: Thu Jun 13, 2002 3:34 pm
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
Posted: Thu Jun 13, 2002 4:12 pm
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)
Posted: Thu Jun 13, 2002 4:38 pm
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.
Posted: Thu Jun 13, 2002 5:48 pm
by BackupUser
Restored from previous forum. Originally posted by scurrier.
Thanks i will try this.
Posted: Sun Jun 16, 2002 8:54 pm
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
Posted: Wed Jun 19, 2002 7:35 am
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
Posted: Wed Jun 19, 2002 9:09 am
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