Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows
Hello
My problem is when someone try to
to shutdown my computer when my exe is Running
 Message.Show("unable to shutdown computer myApplicetion is running")
Posted 11-Oct-12 6:02am
Edited 11-Oct-12 6:58am
v3
Comments
arun_pk at 11-Oct-12 11:06am
   
Please give some more information about your application..
Marcus Kramer at 11-Oct-12 11:09am
   
The shut down your application... I think we're missing some information here.
luisnike19 at 11-Oct-12 11:28am
   
Do you mean you want to display a message if someone tries to shutdown the computer?
giriraj mali at 11-Oct-12 11:49am
   
yes luisnike19 I want to display a message if someone tries to shutdown the computer?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thats simple
 
// SystemEvents class is present in Microsoft.Win32
//e.Cancel=true will terminate the log off or shutdown procedure
SystemEvents.SessionEnding += new SessionEndingEventHandler((o, e) => { e.Cancel = true; MessageBox.Show("unable to shutdown computer myApplicetion is running"); });
  Permalink  
Comments
giriraj mali at 11-Oct-12 13:13pm
   
thanks is relay working
using Microsoft.Win32;
private void Form1_Load(object sender, EventArgs e)
{
SystemEvents.SessionEnding += new SessionEndingEventHandler(this.pcShutDown);
}
protected void pcShutDown(object sender, SessionEndingEventArgs e)
{
e.Cancel = true; MessageBox.Show("unable to shutdown computer myApplicetion is running");
}
 
1)Run project
2) Go to start menu and click the shut down
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To handle (accept/reject) app shutdown when the sytem is shutting down, handle the FormClosing[^] event. In particular, see the CloseReason[^] property.
 
/ravi
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 180
2 DamithSL 180
3 Peter Leow 125
4 Kornfeld Eliyahu Peter 95
0 OriginalGriff 7,355
1 DamithSL 5,254
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100