Hi all.

Well, after searching this message forum for a few days now I have come to the conclusion that none of the examples of rebooting a WindowNT/2k/XP machine actually work. Does anyone have a good example of setting token privileges and actually rebooting the machine or shutting it down? So far, on XP, I can only get it to log off the current user. Yes, even when run with admin privs it only logs off.

Here is what I am using...


mov ovi.dwOSVersionInfoSize, SizeOf ovi
invoke GetVersionEx, offset ovi

.if ovi.dwPlatformId == VER_PLATFORM_WIN32_NT
invoke GetCurrentProcess

invoke OpenProcessToken, eax, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, offset hToken

invoke LookupPrivilegeValue, NULL, offset szShutDownPriv, offset tkp.Privileges[0].Luid
mov tkp.PrivilegeCount, 1
mov tkp.Privileges[0].Attributes, SE_PRIVILEGE_ENABLED
invoke AdjustTokenPrivileges, hToken, FALSE, offset tkp, 0, NULL, 0
.endif

invoke ExitWindowsEx, EWX_SHUTDOWN, 0

.if ovi.dwPlatformId == VER_PLATFORM_WIN32_NT
mov tkp.Privileges[0].Attributes, 0
invoke AdjustTokenPrivileges, hToken, FALSE, offset tkp, 0, NULL, 0
invoke CloseHandle, hToken
.endif
ret


The above code I got from this forum. It doesn't seem to work at all like I said.

If anyone can help me with this, it would be very much appreciated. Or, if there is an example of rebooting a machine via hardware interrupts, that might be a solution too. But, since I am still just learning (M)ASM I know this is going to take me a while.

Thanks all!
Posted on 2003-06-09 16:27:19 by The Beginner
Posted on 2003-06-10 01:35:21 by Bit7
Hi Beginner, if you change the flag you put as argument to the api ExitWindowsEx, you will be more succesful.

Try EWX_REBOOT instead.
Posted on 2003-06-10 06:11:09 by david
Bit7,
Thanks a lot, I will have a go at that translation. :)

david,
What I need to do is shut the machine down or reboot it. Unfortunately, EWX_REBOOT is causing the machine to log off so this has become quite the problem. Anyway, thank you for your answers. :)
Posted on 2003-06-10 13:07:56 by The Beginner
Try this:

invoke GetCurrentProcess
invoke OpenProcessToken,eax,TOKEN_ALL_ACCESS,addr mytoken
invoke LookupPrivilegeValue,NULL,addr lookup,addr tkp.Privileges[0].Luid
mov tkp.PrivilegeCount ,1
mov tkp.Privileges[0].Attributes ,SE_PRIVILEGE_ENABLED
invoke AdjustTokenPrivileges,mytoken,FALSE,addr tkp,0,0,0
invoke ExitWindowsEx,EWX_POWEROFF+EWX_FORCE,NULL
Posted on 2003-06-10 14:23:16 by WinCC

david,
What I need to do is shut the machine down or reboot it. Unfortunately, EWX_REBOOT is causing the machine to log off so this has become quite the problem. Anyway, thank you for your answers.


Weird!! :confused:

I use exactly same code as you, on winXP with admin privileges, and I get rebooted, no log off

EDIT: exactly same code but with EWX_REBOOT
Posted on 2003-06-10 15:18:58 by david

EWX_REBOOT is causing the machine to log off so this has become quite the problem. Anyway, thank you for your answers. :)

Perhaps there is some system policy taht prohibits reboot, i.e. you're not allowed to rebot the computer.
Posted on 2003-06-10 16:26:56 by scientica


Perhaps there is some system policy taht prohibits reboot, i.e. you're not allowed to rebot the computer.


I am the system administrator with full GOD-like privies. Nothing has been configured in my system that would disallow a reboot especially since I have an old delphi app laying around which works. This is why this is perplexing me! >:o

Thanks again!
Posted on 2003-06-10 16:45:55 by The Beginner
Well.... figured it out. For some reason, I started my code off like so:



.386 <---- Problem
.model flat, stdcall
option casemap: none


After my last post, I chaged it to:


.486 <---- Problem GONE
.model flat, stdcall
option casemap: none


So, if anyone ever has this problem... now you know one more possible solution. Thanks for all of the help everyone, it is truly appreciated.
Posted on 2003-06-10 20:29:50 by The Beginner

Well.... figured it out. For some reason, I started my code off like so:



.386 <---- Problem
.model flat, stdcall
option casemap: none


After my last post, I chaged it to:


.486 <---- Problem GONE
.model flat, stdcall
option casemap: none


So, if anyone ever has this problem... now you know one more possible solution. Thanks for all of the help everyone, it is truly appreciated.



hmm, that is extremely weird, does that mean for some reason we should always go with the higher directive?
Posted on 2003-06-10 21:10:40 by Drocon
So far, on XP, I can only get it to log off the current user. Yes, even when run with admin privs it only logs off.
.486 <---- Problem GONE


That doesn't make any sense. :confused:
Posted on 2003-06-11 02:01:54 by iblis