473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Delay Windows Restart/Shutdown

Gurus,

I am trying to delay Windows Shutdown/Restart to perfrom cleanup and I
am using the following code:

[System.Security.Permissions.PermissionSet(System.S ecurity.Permissions.SecurityAction.Demand,
Name = "FullTrust")]

protected override void WndProc(ref Message ex)
{

if (ex.Msg == WM_QUERYENDSESSION)

{

//cancel the Shutdown/Restart

Message MyMsg = new Message();

MyMsg.Msg = WM_CANCELMODE;

base.WndProc(ref MyMsg);

//do the necessary work

//Run the Issued Restart/Shutdown command

base.WndProc(ref ex);

}

else

{

//send the message as normal

base.WndProc(ref ex);

}

}

But I realize that the cancel message is not being passed to other
windows if I do this and other applications start displaying error/
crash messages because they begin to shutdown. It looks like
'base.WndProc' sends message a message only after you come out of the
WndProc method and hence you cannot pass both WM_CANCELMODE and
Message ex within the same method call.

The Message 'ex' cannot be unfortunately used to distinguish between
Restart/Shutdown and I need to perform whatever was requested after
performing the required operations.

Please let me know if there are any alternatives.

Any help is greatly appreciated. Thanks in advance.
Jun 27 '08 #1
3 4262
Pete,
Thanks for your reply.

WM_CANCELMODE message seems to cancel the shutdown if it is sent
alone.
And also WM_QUERYENDSESSION message seems to continue the windows
Shutdown, again, when sent alone.

My application basically stops other applications gracefully on the
system and is about 10 seconds of cleanup work.
The only problem that I have is that other applications get the
shutdown message at the same time as the main app and hence the main
app is not able to close some of the other applications that it starts
and monitors.

I'll meanwhile look at Application.SessionEnding event and see if I
could make use of it.

Do you have any other suggestions?
Jun 27 '08 #2
On Mon, 19 May 2008 05:10:08 -0700, IdleBrain <in**************@yahoo.com>
wrote:
Pete,
Thanks for your reply.

WM_CANCELMODE message seems to cancel the shutdown if it is sent
alone.
I can't explain this. Perhaps there's something inside the .NET default
window proc that signals Windows to interrupt the shutdown when it gets
the message. However, as you've seen...if you cancel the shutdown, you
can't just continue by later calling the base implementation of
WndProc(). That's not how the shutdown works.
And also WM_QUERYENDSESSION message seems to continue the windows
Shutdown, again, when sent alone.
But it's not the act of passing that message to the base WndProc() that
causes the shutdown to continue. It's simply that you haven't canceled
the shutdown. Absent an application canceling the shutdown, it will
proceed no matter what you do
My application basically stops other applications gracefully on the
system and is about 10 seconds of cleanup work.
The only problem that I have is that other applications get the
shutdown message at the same time as the main app and hence the main
app is not able to close some of the other applications that it starts
and monitors.
Why not? If it's because those applications have a prompt up, you could
try sending _those_ windows a WM_CANCELMODE. If it's because those
applications are already closed, then why is it a problem for it to not be
able to close them?

You've certainly entered in a gray area that IMHO illustrates the hazards
of trying to manage other processes from a given process. You're not
specific about the nature of the processes, so I don't know how much
control you have over them. But ideally you would be able to rewrite all
of the applications involved so that they coordinate their shutdown
process as necessary.

If the other applications are third-party applications without a
well-defined API for interacting with them, well...you're likely to have
problems, sorry to say.

Pete
Jun 27 '08 #3
If the other applications are third-party applications without a
well-defined API for interacting with them, well...you're likely to have
problems, sorry to say.
Yeah the other tools that my App is trying to control are third party
tools and I cannot cancel the shutdown individually from them.
I just donot understand why MS makes it hard to find out if the issued
message was a Shutdown/Restart.
My Life would have been much easier if I knew that !!

Thanks for your reply. I appreciate your time.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: JonBoy | last post by:
Is it possible to put the logoff/shutdown/restart buttons on an ASP page or something similar? If so can anyone point me in the direction of some code please or where I can read how to do it ...
3
by: Senthil | last post by:
Hi, I would like to know the code for reboot and shutdown windows xp professional using VB.Net. thanx Senthil
0
by: bj7lewis | last post by:
I have C# service(VS.NET 2002) that I want to bk up a few files when Windows is shutdown/restart(thur any of the correct ways to Shutdown/restart window) and choose to do the actual backup in a...
6
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
5
by: Phil Tusa | last post by:
Greetings to all .... I have a need to issue a shutdown and/or Restart Windows XP inside my application. Any help or example code would be appreciated! -- Phil
4
by: Frank | last post by:
My program gets a WM_QUERYENDSESSION message and asks the user if it is OK to shutdown. While he's thinking about it, Windows displays a box saying the program is not responding, and if not...
1
by: CyberSoftHari | last post by:
I want to get applications running (Showing) in Task bar (and show those applications running) and Cancel windows LogOff, Shutdown, Restart when user try to Click windows LogOff, Shutdown, Restart
1
by: chandru | last post by:
hai friends, Iam developing a application using .NET remoting ,in which it shuts down,logs off , restart , locks remote PC.i tried to use windows ExwindowsEXAPI for shutdown,logoff , restart ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.