Click here to Skip to main content
15,886,056 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello
My problem is when someone try to
to shutdown my computer when my exe is Running
C#
Message.Show("unable to shutdown computer myApplicetion is running")
Posted
Updated 11-Oct-12 5:58am
v3
Comments
arun_pk 11-Oct-12 11:06am    
Please give some more information about your application..
fjdiewornncalwe 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?

Thats simple

C#
// 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"); });
 
Share this answer
 
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
To handle (accept/reject) app shutdown when the sytem is shutting down, handle the FormClosing[^] event. In particular, see the CloseReason[^] property.

/ravi
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900