PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average.

Detect Shutdown from .NET

 
 
Adnan Hebibovic
Guest
Posts: n/a
 
      25th Mar 2005
Hello developers

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

Thanks


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QU1lcmNlcg==?=
Guest
Posts: n/a
 
      25th Mar 2005
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
>
>
>

 
Reply With Quote
 
Adnan Hebibovic
Guest
Posts: n/a
 
      25th Mar 2005
When the form is minimized to systray there is no Win32.SessionEnded event
....

Thanks
"AMercer" <(E-Mail Removed)> wrote in message
news:AF974A9D-D2A1-41B6-8317-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?QU1lcmNlcg==?=
Guest
Posts: n/a
 
      25th Mar 2005
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.SessionEnded event
> ....
>
> Thanks
> "AMercer" <(E-Mail Removed)> wrote in message
> news:AF974A9D-D2A1-41B6-8317-(E-Mail Removed)...
> > 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
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      26th Mar 2005
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(object sender, System.EventArgs e)
{
Microsoft.Win32.SystemEvents.SessionEnded +=new
Microsoft.Win32.SessionEndedEventHandler(SystemEvents_SessionEnded);
this.Resize +=new EventHandler(Form1_Resize);
}

private void SystemEvents_SessionEnded(object sender,
Microsoft.Win32.SessionEndedEventArgs e)
{
MessageBox.Show("End");
}

private void Form1_Resize(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.notifyIcon1.Visible=true;
}
else
this.ShowInTaskbar = true;
this.notifyIcon1.DoubleClick+=new EventHandler(notifyIcon1_DoubleClick);
}

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}

HTH.

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

 
Reply With Quote
 
Adnan Hebibovic
Guest
Posts: n/a
 
      26th Mar 2005
Thanks I see now where is the problem with my code.

"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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(object sender, System.EventArgs e)
> {
> Microsoft.Win32.SystemEvents.SessionEnded +=new
> Microsoft.Win32.SessionEndedEventHandler(SystemEvents_SessionEnded);
> this.Resize +=new EventHandler(Form1_Resize);
> }
>
> private void SystemEvents_SessionEnded(object sender,
> Microsoft.Win32.SessionEndedEventArgs e)
> {
> MessageBox.Show("End");
> }
>
> private void Form1_Resize(object sender, EventArgs e)
> {
> if(this.WindowState == FormWindowState.Minimized)
> {
> this.ShowInTaskbar = false;
> this.notifyIcon1.Visible=true;
> }
> else
> this.ShowInTaskbar = true;
> this.notifyIcon1.DoubleClick+=new EventHandler(notifyIcon1_DoubleClick);
> }
>
> private void notifyIcon1_DoubleClick(object sender, EventArgs e)
> {
> this.WindowState = FormWindowState.Normal;
> this.notifyIcon1.Visible = false;
> }
>
> HTH.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      29th Mar 2005
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."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect logoff/shutdown j Microsoft Outlook Program Addins 1 21st Jul 2009 02:42 PM
Detect Remote Shutdown Chris Johnson Microsoft VB .NET 4 18th Jan 2006 03:29 PM
detect shutdown of other application =?Utf-8?B?Z2VvcmcgYW5kZXJzc29u?= Microsoft Dot NET Framework 1 25th Nov 2004 07:59 AM
Detect logoff or shutdown Jerry Camel Microsoft VB .NET 1 14th May 2004 10:20 PM
How to Detect Improper Shutdown birju jani Windows XP Customization 0 16th Aug 2003 12:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 AM.