Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What API do I call to abort logoff/shutdown?

Status
Not open for further replies.

kbern3

Technical User
Jun 27, 2007
1
I need to write a script that will run every time someone tries to log off or shutdown a computer. In the past people have logged off computers while QE tests or automation on virtual machines were running. So it would always be a real pain when these VMs were shut off without warning. I need to write a script that runs everytime a user tries to logoff/shutdown. This script would check for VMware’s executable file (vmware-vmx.exe) and (if the process is found) prompt a warning to the user and stop the logoff shutdown process from happening.

I’ve done A LOT of research on the internet about logoff/shutdown scripts, posted on message boards and I’ve emailed some people that I know. However, I’ve found three different API calls/messages and I can’t move forward with my scripts until I know which one to use:

*AbortSystemShutdown* - This call aborts a shutdown initiated by InitiateSystemSutdown or InitiateSystemShutdownEx calls. ASS is thrown during the timeout period specified by ISS or ISSE. I don’t know if it will work for the console session since ISS and ISSE are only used in RDP connections.

*ExitWindowsEx* - Can shutdown, logoff, or restart a computer and pass reasons to the event log as to why any of these happened. I havn't found an API that aborts this call. I know that EWE sends the *WM_QUERYENDSESSION* message which can potentially abort a logoff/shutdown if the a value of “0” is returned. How do I respond to this message with “0”? I haven’t found any examples.

*SystemEvents.SessionEnding* - Can cancel shutdown
My qualms: can’t cancel logoff and too many caveats: console apps don’t raise this event, cancel only works sometimes, and there’s no guarantee this event will fire before the closing event fires.

I would really appreciate some help and feedback.

P.S. Just in case your wondering, I’m aware of the fact that I can’t directly call an API from a script and that I have to use either MS Office as proxy to load the code into a macro to make the calls or use an ActiveX control to act as a wrapper to make the calls
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top