how to get ExitWindowsEx to work properly

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Tobias
Junior Coder
Posts: 22
Joined: Mon Jul 19, 2004 1:44 pm
Location: The Netherlands

how to get ExitWindowsEx to work properly

Post by Tobias » Wed Apr 29, 2009 10:03 am

Hi,

I was looking for a way to shut down a PC after properly closing down a running program. As Windows functions is beyond me, I was very happy to find a post by JRL containing the following code:

LibFunc>user32,ExitWindowsEx,EWEres,0,1

I've got the close-the-running-program-part working. However the shutdown-part does not run as expected.
I found the following info on the arguments for ExitWindowsEx:
The second argument is for the shutdown type. I found these possible values:
0=logoff
1=shutdown
2=reboot
4=logoff and forced termination of processes
8=poweroff
10=same as 4 + terminate hanging processes
40=restart (incl applications registered for restart)

The last argument is for the shutdown reason, which seems to be used for logging purposes mostly.

I am only able to get the logoff (argument value 0) working, all the other arguments don't seem to work and I don't understand why. could anybody enlighten me?

thanks in advance,
Tobias

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Apr 29, 2009 10:15 am

Is there any reason why you cannot use the ShutDownWindows command?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Tobias
Junior Coder
Posts: 22
Joined: Mon Jul 19, 2004 1:44 pm
Location: The Netherlands

Post by Tobias » Wed Apr 29, 2009 10:34 am

No there isn't (except for my ignorance, not being aware of this command). It is working like a charm with ShutDownWindows.

thanks Marcus.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts