Reboot?
-
BackupUser
- PureBasic Guru

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

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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.
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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Stan.
Hi,
Bests.
Stan
Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
Hi,
Plz take no offence, why do you need to do that ? (I'm just curious).How do i reboot the computer from within my code?
Bests.
Stan
Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
-
BackupUser
- PureBasic Guru

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

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

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

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
hWnd=FindWindow_(0,"Untitled - Notepad")
PostMessage_(hWnd,16,0,0)
You could always get the handle of the other window then post a close message to it... here is a quick example: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
hWnd=FindWindow_(0,"Untitled - Notepad")
PostMessage_(hWnd,16,0,0)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
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.
Tested on Win98SE (@work) and it works fine.I tried your code but it didn't work
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

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Schlowski.
Some weeks ago I needed such a little rebooter, so here are the sources:
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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm