Click here to Skip to main content
15,886,037 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I borrowed this piece of code into my application. This application runs on public library
computers to monitor time each user spends on a computer, so we don't want users closing the application. I published the application with this code and it disables Alt+F4 when I log in as administrator which is what I want but does not do so when any other user logs on . Don't see how a piece of code can run under one user and not another. Ist it ppossible

C#
protected override void OnFormClosing(FormClosingEventArgs e)
        {
            switch (e.CloseReason)
            {
                case CloseReason.UserClosing:
                    e.Cancel = true;
                    return;
            }
            base.OnFormClosing(e);
        }
Posted
Comments
HobbyProggy 11-Dec-13 9:12am    
A little more information might help.
This literally tells me nothing but it doesn't work :/
BillWoodruff 11-Dec-13 9:16am    
If a user is logged on, what does e.CloseReason evaluate to ?

While you sort out what's going on with e.CloseReason, you could implement a "hot-fix" for Alt-F4 by setting the Form's KeyPreview Property to 'true, and wiring-up the KeyDown Event:
C#
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    e.Handled = (e.Alt == true && e.KeyCode == Keys.F4);
}
 
Share this answer
 
Sooooo...what are you going to do when the user launches Task Manager and closes your app by force?? The code in your app won't stop that from happening.

You also cannot put any code in there to prevent a user from running the command line tools TASKLIST and TASKKILL.
 
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