473,729 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name = "FullTrust" )]

protected override void WndProc(ref Message ex)
{

if (ex.Msg == WM_QUERYENDSESS ION)

{

//cancel the Shutdown/Restart

Message MyMsg = new Message();

MyMsg.Msg = WM_CANCELMODE;

base.WndProc(re f MyMsg);

//do the necessary work

//Run the Issued Restart/Shutdown command

base.WndProc(re f ex);

}

else

{

//send the message as normal

base.WndProc(re f 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 4286
Pete,
Thanks for your reply.

WM_CANCELMODE message seems to cancel the shutdown if it is sent
alone.
And also WM_QUERYENDSESS ION 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.Ses sionEnding 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_QUERYENDSESS ION 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
2540
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 Cheer JonBoy
3
1189
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
1800
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 batch file and then use Process class to start the batch file... Now I have set CanShutdown to true and add my OnShutdown handler but it won't run the batch file(I made sure that the batch file would copy a file somewhere that wouldn't be there...
6
8760
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 talk to the UPS over a special device driver. Through this device driver I can detect that the UPS is going to notify Windows 2000 server to shut down. So I start doing a graceful termination. But Windows shuts down pretty quickly and there...
2
11414
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, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use managed code instead. I couldn't find any easy way of doing this but searching the Internet with...
5
17411
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
1887
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 answered shuts down my program. I need to delay that while until the user answers my program's dialog box. How does Windows check to see if an app is responding.
1
10349
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
3060
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 and SetSuspendState for lock PC and the later worked perfectly but the problem is ExwindowsEx only Logsoff the PC and shutdown and restart is not working .Although i achieved the result using shutdown.exe ,but iam not convinced,so could anyone say...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.