473,785 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preventing Logoff / Shutdown until C# Windows App is closed

I developed a C# Windows App that requires a user to input their real
name and what they did to the server while they were online.

I am going to launch the app att shutdown via a logoff script.

I want to prevent the computer from logging off or shutting down until
the app is closed.

The best example I have is when you have an unsaved notepad.exe
document open and logoff or shutdown, an End Program dialog pops up
that says "The system cannot end this program because it is waiting for
a response from you". The computer will sit there forever waiting for
user response. I want that to happen with my app so they are forced to
enter data before the logoff/shutdown process continues.

How can I do this?

Jan 19 '07 #1
2 8421
Anyone?

mi************* **@gmail.com wrote:
I developed a C# Windows App that requires a user to input their real
name and what they did to the server while they were online.

I am going to launch the app att shutdown via a logoff script.

I want to prevent the computer from logging off or shutting down until
the app is closed.

The best example I have is when you have an unsaved notepad.exe
document open and logoff or shutdown, an End Program dialog pops up
that says "The system cannot end this program because it is waiting for
a response from you". The computer will sit there forever waiting for
user response. I want that to happen with my app so they are forced to
enter data before the logoff/shutdown process continues.

How can I do this?
Jan 23 '07 #2
I had to figure it out myself...

With a form called 'Form1', you can use this code to do it:

(bSubmitted is a boolean that gets set to TRUE after the app submits
an entry)

private void Form1_FormClosi ng(object sender,
FormClosingEven tArgs e)
{
if (bSubmitted == false)
{
if (MessageBox.Sho w("You are closing this app without
submitting an entry.\n\nAre you sure you wish to exit without
submitting?", "Warning: Not Submitted", MessageBoxButto ns.YesNoCancel,
MessageBoxIcon. Stop) == DialogResult.Ye s)
return;
else
e.Cancel = true;
}
}

On Jan 22, 3:53 pm, mikemiller.inn. ..@gmail.com wrote:
Anyone?

mikemiller.inn. ..@gmail.com wrote:
I developed a C# Windows App that requires a user to input their real
name and what they did to the server while they were online.
I am going to launch the app att shutdown via a logoff script.
I want to prevent the computer from logging off or shutting down until
the app is closed.
The best example I have is when you have an unsaved notepad.exe
document open and logoff or shutdown, an End Program dialog pops up
that says "The system cannot end this program because it is waiting for
a response from you". The computer will sit there forever waiting for
user response. I want that to happen with my app so they are forced to
enter data before the logoff/shutdown process continues.
How can I do this?- Hide quoted text -

- Show quoted text -

Mar 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2767
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think this would be simple enough if the ASP didn't have any user input, but it does.
7
2540
by: JonBoy | last post by:
Is it possible to put the logoff/shutdown/restart buttons on an ASP page or something similar? If so can anyone point me in the direction of some code please or where I can read how to do it Cheer JonBoy
2
11415
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use managed code instead. I couldn't find any easy way of doing this but searching the Internet with...
6
11271
by: Jm | last post by:
Hi All I have a simple vb.net app that once run for some reason does not allow me to log off or shutdown the pc ? When i try to do so it will close my app and then will only shutdown or logoff if i attempt to do so once again ? Does anybody have any does why this would be so ?
3
1746
by: Mantorok | last post by:
Hi all Is there any way to prevent a user from closing down an application (via task manager)? Thanks Kev
0
1121
by: sam | last post by:
I have a vb.net app that runs without a visible window. When the user logs off or attempts a shutdown, the app is not quitting and prevents the logoff/shutdown until the task is killed. Is there a method to detect these system events and cause my app to quit gracefully?
3
3284
by: Bill Davidson | last post by:
All: I have a problem in which a worker thread in my (.dll) assembly isn't allowing the main (.exe) assembly from terminating. Here's the scenario: 1) App.Exe is launched. 2) App.Exe calls into my .dll (Sub.Dll)
1
10350
by: CyberSoftHari | last post by:
I want to get applications running (Showing) in Task bar (and show those applications running) and Cancel windows LogOff, Shutdown, Restart when user try to Click windows LogOff, Shutdown, Restart
1
1400
by: cg2002 | last post by:
Hi, How can I abort the shutdown/logoff in windows vista? Using the WM_QUERYENDSESSION only works in XP. TIA Carlos
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.