Click here to Skip to main content
12,951,732 members (62,434 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 5:02am
Updated 11-Oct-12 5:58am
v3
Comments
arun_pk 11-Oct-12 11:06am
   
Please give some more information about your application..
Marcus Kramer 11-Oct-12 11:09am
   
The shut down your application... I think we're missing some information here.
luisnike19 11-Oct-12 11:28am
   
Do you mean you want to display a message if someone tries to shutdown the computer?
giriraj mali 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2017
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