There might be many reasons, e.g. any application you have open may also abort the shutdown (since you are not forcing it), maybe your system does not support the power-off feature or your program lacks the shutdown privilege etc.
To get a bit more clue about what is going wrong, check which error code GetLastError() returns immediately after the ExitWindowsEx() call ... I.e.
Note that even if ExitWindowsEx() returns non-zero, it does not necessarily mean that the shutdown will eventually occur. (Read the MSDN documentation carefully and (try to) understand it.)
You might also try the How to Shut Down the System sample function (it shows how to enable the shutdown privilege among other things).
Tried to implement your code mitrmkar but still no avial.
I am using codeblocks and it worked for several other previous projects but havent used it in 6 months.
dubeyprateek - You just thrown the MSDN example into a function so it runs? Ill check if this works but it sorta cheating but I guess this is something to work off if it does.
But begs the question if it works, why didnt my code work?
Ill let you know how it goes... brb
Well wont even compile correctly I didnt notice before
but each time I complie both files there is a big red bar
near the ExitWindowsEx() Parameters.
1) Your code lacks the required privilage. You would need Shutdown Privilage enabled for the process which initiates the shutdown.
2) On server OS not everyone has shutdown privilage, you need to make sure that you are Admin if you are using server version.
3) This MSDN example is complete.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.