Which Logoff/Shutdown API should I call?
- From: camille.reeves@xxxxxxxxx
- Date: Wed, 27 Jun 2007 07:30:45 -0700
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 virtual machines were running QE tests or automation.
So it would always be a real pain when these VMs were shut off without
warning. I need to write a script that 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 shut down or log off 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 people that I
know. So far I've found out that it should be written in vbscript, it
should be added to all computers via group policy, I should write the
script in this way [1. get a process list, 2. search the list for the
VMware process, 3. if process is found alert the user and cancel
shutdown, 4. if not, do nothing], and lastly I have to make API calls
to prevent shutdown/logoff from happening which gets to the point of
my post. I've found four different API calls/messages and I really
don't know which one I should use. I can't move forward with my
scripts until I find out which one I should 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.
My qualms: This doesn't work for logging off and I don't know if it
will work for the console session since ISS and ISSE are only used in
RDP connections. Does anyone know if this call work to abort a
shutdown initiated by ExitWindowsEx?
ExitWindowsEx - Can shutdown, logoff, or restart a computer and pass
reasons to the event log as to why any of these happened
My qualms: I haven't found an API that aborts this call. Can you
cancel or abort this call? I know that this API 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" in a script?
WM_QUERYENDSESSION - Whenever a user attemps to logoff or shutdown,
the OS sends this message (via the ExitWindowsEx API) to all open
windows. If the message handler returns "0", windows will abort the
logoff/shutdown.
My qualms: How would I respond to this message in a script? 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.
Based on my own judgment, I think I should go with WM_QUERYENDSESSION
because it works to cancel both logoff or shutdown which is what I
need. However, I'm a novice at vbscript (started learning three weeks
ago) and this is the first time I've dealt with APIs. *I would
appreciate any help/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. Sorry this
post is so long.
.
- Prev by Date: Re: W2003 Enterprise 4GB RAM
- Next by Date: Re: Issue with VSS on W2K3
- Previous by thread: Allowing users to configure USB devices
- Next by thread: Re: Rejoining hosts to domain
- Index(es):
Relevant Pages
|