473,841 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detect Shutdown from .NET

Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks
Jul 21 '05 #1
6 9438
Try handling the Microsoft.Win32 .SessionEnded event.

"Adnan Hebibovic" wrote:
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks

Jul 21 '05 #2
When the form is minimized to systray there is no Win32.SessionEn ded event
....

Thanks
"AMercer" <AM*****@discus sions.microsoft .com> wrote in message
news:AF******** *************** ***********@mic rosoft.com...
Try handling the Microsoft.Win32 .SessionEnded event.

"Adnan Hebibovic" wrote:
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks

Jul 21 '05 #3
Your first post asked how to "detect Windows shutdown". My response answered
that. I just tried it out, and it worked (although I used session ending
vice session ended). I run my program, I try to shut down windows, and the
event fires. Your second post asks about minimizing. For that, you should
handle the form's resize event and check the form property WindowState. If
it is FormWindowState .Minimized, then the window is minimized.

Windows shutdown and minimizing a window are different things. What exactly
are you trying to detect?

"Adnan Hebibovic" wrote:
When the form is minimized to systray there is no Win32.SessionEn ded event
....

Thanks
"AMercer" <AM*****@discus sions.microsoft .com> wrote in message
news:AF******** *************** ***********@mic rosoft.com...
Try handling the Microsoft.Win32 .SessionEnded event.

"Adnan Hebibovic" wrote:
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks


Jul 21 '05 #4
Hi,

I think Adnan might be asking that when he minimized a window to the system
tray, the SessionEnded event is not fired. Right?

I have tried it on my machine, and it works fine under any circumstances.
Please try my code in a new windows application.

private void Form1_Load(obje ct sender, System.EventArg s e)
{
Microsoft.Win32 .SystemEvents.S essionEnded +=new
Microsoft.Win32 .SessionEndedEv entHandler(Syst emEvents_Sessio nEnded);
this.Resize +=new EventHandler(Fo rm1_Resize);
}

private void SystemEvents_Se ssionEnded(obje ct sender,
Microsoft.Win32 .SessionEndedEv entArgs e)
{
MessageBox.Show ("End");
}

private void Form1_Resize(ob ject sender, EventArgs e)
{
if(this.WindowS tate == FormWindowState .Minimized)
{
this.ShowInTask bar = false;
this.notifyIcon 1.Visible=true;
}
else
this.ShowInTask bar = true;
this.notifyIcon 1.DoubleClick+= new EventHandler(no tifyIcon1_Doubl eClick);
}

private void notifyIcon1_Dou bleClick(object sender, EventArgs e)
{
this.WindowStat e = FormWindowState .Normal;
this.notifyIcon 1.Visible = false;
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5
Thanks I see now where is the problem with my code.

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:PP******** ******@TK2MSFTN GXA03.phx.gbl.. .
Hi,

I think Adnan might be asking that when he minimized a window to the
system
tray, the SessionEnded event is not fired. Right?

I have tried it on my machine, and it works fine under any circumstances.
Please try my code in a new windows application.

private void Form1_Load(obje ct sender, System.EventArg s e)
{
Microsoft.Win32 .SystemEvents.S essionEnded +=new
Microsoft.Win32 .SessionEndedEv entHandler(Syst emEvents_Sessio nEnded);
this.Resize +=new EventHandler(Fo rm1_Resize);
}

private void SystemEvents_Se ssionEnded(obje ct sender,
Microsoft.Win32 .SessionEndedEv entArgs e)
{
MessageBox.Show ("End");
}

private void Form1_Resize(ob ject sender, EventArgs e)
{
if(this.WindowS tate == FormWindowState .Minimized)
{
this.ShowInTask bar = false;
this.notifyIcon 1.Visible=true;
}
else
this.ShowInTask bar = true;
this.notifyIcon 1.DoubleClick+= new EventHandler(no tifyIcon1_Doubl eClick);
}

private void notifyIcon1_Dou bleClick(object sender, EventArgs e)
{
this.WindowStat e = FormWindowState .Normal;
this.notifyIcon 1.Visible = false;
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #6
You're welcome, Adnan.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #7

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

Similar topics

2
4648
by: Austin | last post by:
I wrote a program running on windows. I put the link of the program in "Start up" folder and let it executed minimized. Every time when I open the computer, my program will be running in system tray. But if the user would like to shutdown the computer, the OS will show an error about exception. At first, I think windows will terminate all processes when it shutdown.
2
3801
by: Austin | last post by:
My program is running on windows and it is wrritten by Python and wxPython, built by py2exe. If my program is executed minimized, and the user want to shutdown or reboot. Meanwhile, my program is running and it has several threads running, too. The shutdown or reboot will cause a error of my program. Is there any way to dectect windows shutdown or reboot? If I detect the message of shutdown, I could close all threads of my program.
0
503
by: Will Haney | last post by:
I have a .NET application that needs to perform some last moment duties upon termination. The application has no forms with one Module containing the Sub Main. How can I detect/trap the termination of the application during a system shutdown, logoff, end task or end process?
2
19944
by: Mike Stephens | last post by:
I have an application to minimizes when X is clicked. If the user wants to close the application they click the Exit Application button.This works fine and does exactly what I need. I have since discovered it is holding Windows open when you shutdown. If the application is running and the user shutsdown Window it holds up everything. If the application is not running and the user shutsdown Windows is shutsdown in a timely manner. How...
1
1939
by: Jerry Camel | last post by:
How do you detect when a system is being logged off or shutdown? In VB 6 there was a QueryUnload event that would work if you had a form, but I'm running in a Sub Main scenario... I can't find any events to code for... Is there a way to register with the system to be notified of the logoff/shutdown? Thanks. Jerry
12
17069
by: Patrick Dugan | last post by:
I have an vb.net application that is a module that uses a "application.run" in the sub main to start. There is no form involved (just a system tray icon) How can you detect when the application is being closed? It is easy enough if the user selects "exit" from this tray icon but how can you detect if Windows is closing the program down? Normally I would simply do something in the Form.Closing event but without a form how can you...
6
355
by: Adnan Hebibovic | last post by:
Hello developers How can I detect Windows shutdown from .NET and I mean clean .NET not catching the events with Win32 API ... Thanks
13
2440
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record how many bytes are actually sent. I can detect abort of the script using a shutdown handler. In the shutdown handler, I tried ob_get_length, but it returns false. I tried to read the server's log file, but it is does not contain the...
4
2824
by: Chris Johnson | last post by:
Hey all, I have a small app I have developed that periodically pings a list of server and returns their status. Given my environment I have setup the program such that a server can be down 4 minutes before I get an alert. My problem now is that is a server is rebooted, it will be back up before the 4 minute window and I will not be aware that it has rebooted. I am looking for a way (as an administrator, or not, if possible) to detect
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9706
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
10927
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...
1
10667
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9446
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
7848
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
5691
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...
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3140
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.