I've a VBS script that defrags the hard drive and what I'm wanting to
happen is the following:

1. The user initiates a system shutdown.
2. Some process intercepts the shutdown and performs a task or tasks.
3. The shutdown resumes and powers off the system.

I found a freeware app called "LastChance" that intercepts shutdown
requests in the manner I specified however after the VBS script completes,
the system does not shut down. I tried to circumvent this issue by using
systernals PSShutdown by adding the following line to the end of my VBS file:

wshShell.Run "%windir%\System32\psshutdown.exe -k"

That should work but instead it simply logs the user out and leaves him/her
at the Novell login screen.

Any thoughts on what's wrong and/or how to fix it. Alternately, ideas on
how else I might go about scheduling tasks to run at shutdown would be
greatly appreciated. Can this be done via the registry? Are there keys
that can be created that will cause indicated tasks/processes/programs to
run when a shutdown command is intercepted? When I get this figured out I
plan to expand it a bit such that the system deletes junk files, etc. and
defrags prior to each shutdown.

Thanks in advance for any help.