From: Milan on
Hi all,

I am trying to write application which will intercept ShutDown event and
then cancel that even do some backup work and then fire again shut down
event. The problem I am facing is that after capturing shutdown event
following line does not help me to cancel it completlly:
System.Diagnostics.Process.Start(@"C:\WINNT\system32\shutdown.exe", "-a");

So ShutDown seems to be canceld but my application report error code
0xC0000142 in User32.dll, and can not proceed with backup operation.

Is there any way to cancel shutdown event and that application have all
needed dlls available so that my application can do its job completlly ?

br,
Milan.
From: Jackie on
On 5/28/2010 13:39, Jackie wrote:
> ...

Maybe you could also look into CloseReason (CloseReason.WindowsShutDown)
in your form's OnClosing event, but I am not sure how that works.
From: Jackie on
On 5/28/2010 13:39, Jackie wrote:
>...

Apparently, the minimum supported client for
ShutdownBlockReasonCreate/Destroy is Windows Vista.

Some reading on "Application Shutdown Changes in Windows Vista":
http://msdn.microsoft.com/en-us/library/ms700677%28VS.85%29.aspx

At least you can probably figure it out on your own now.

Also, please note that my code example is simplified.
From: Jackie on
On 5/28/2010 15:51, Jackie wrote:
> ...

Just so you know, there are some errors in my code (it will still work
however). Just read the documentation. I will however experiment with it
because I am kind of interested. :)
From: Jackie on
On 5/28/2010 17:17, Jackie wrote:
> Just so you know, there are some errors in my code (it will still work
> however). Just read the documentation. I will however experiment with it
> because I am kind of interested. :)

Before someone tells me what I already know (that there is a mistake in
my code), I'll just let you know what it is:
You should call ShutdownBlockReasonCreate when handling
WM_QUERYENDSESSION and not in WM_ENDSESSION.