且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Exe运行时无法关闭计算机

更新时间:2022-12-23 12:18:51

那很简单

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"); });


要在系统关闭时处理(接受/拒绝)应用程序关闭,请处理 ^ ]事件.特别是,请参见 CloseReason [
To handle (accept/reject) app shutdown when the sytem is shutting down, handle the FormClosing[^] event. In particular, see the CloseReason[^] property.

/ravi