prevent winows to shutdown

sizer

Well-known member
Joined
Mar 6, 2003
Messages
123
Location
Croatia
hi,
i have a problem with stopping windows to shutdown , i founded some code

C#:
  private int WM_QUERYENDSESSION  = 0x11;
  private int WM_CANCELMODE  = 0x1F;
  
  protected override void WndProc(ref Message m)
  {
        if (m.Msg == WM_QUERYENDSESSION)
         {
           Message x = new Message();
    		
                x.Msg = WM_CANCELMODE;
    		base.WndProc(x);
         

         }
         else
         {
           base.WndProc(m);
         }
  }

but this code doesnt work ,,, windows is still shuting down ( logging off or restart )!

Any ideas?
tx...
 
Why are you trying to do this? And does it somehow relate to COM Interop issues like Automating MS Office Applications?
 
Mike_R said:
Why are you trying to do this? And does it somehow relate to COM Interop issues like Automating MS Office Applications?

i need to know when/if that happens , because i want to close my application properly!
 
Ok, I think Im starting to get it... And Im probably not the right guy to help here. But guessing a bit: Are you saying that when Windows Shuts down you want to be able to hold up the process long enough so that you can shut down your resources properly? The 20 seconds or so default is not sufficient?

I really dont know that this process can be prevented, but Im not really one to know such things...

Can I ask what resources you are trying to shut down? What Applications are you Auttomating/Controlling? Are they MS Office Applications?
 
Problem "solved"

ok, i found the problem ,,code above works fine , but if you try to ask user with MessageBox "Are you sure" for example then code above doesnt work,, so im traping WM_ENDSESSION and immidetly after that im sending WM_CANCELMODE.
If user click "Yes" for example :) im calling other class that shutdown the computer...

:cool: :D
 
Last edited by a moderator:
Back
Top