Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Prevent Application Close / Detech Application started

Prevent Application Close / Detech Application started

Scheduled Pinned Locked Moved C#
csharphelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Major_A398
    wrote on last edited by
    #1

    I'm looking for a way in C#.NET 2.0 to not allow my application from being closed by Task Manager by doing an End Task. Was thinking about displaying an error message saying you can't close this task. Any Ideas? Also I'm looking for a way to detect certain applications are started and not allow them to start with a message box that says something like "Not aloud to run this app".

    L 1 Reply Last reply
    0
    • M Major_A398

      I'm looking for a way in C#.NET 2.0 to not allow my application from being closed by Task Manager by doing an End Task. Was thinking about displaying an error message saying you can't close this task. Any Ideas? Also I'm looking for a way to detect certain applications are started and not allow them to start with a message box that says something like "Not aloud to run this app".

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      Major_A398 wrote:

      I'm looking for a way in C#.NET 2.0 to not allow my application from being closed by Task Manager by doing an End Task. Was thinking about displaying an error message saying you can't close this task. Any Ideas?

      On your parent form, implement a handler for the Closing event. The Closing EventArg allows you to set e.Cancel = true;

      Major_A398 wrote:

      Also I'm looking for a way to detect certain applications are started and not allow them to start with a message box that says something like "Not aloud to run this app".

      This would require unsafe code hooked into the WinAPI. Can't help you there. An alternative is to have all applications as MDI children and the controller is the MDIParent. In this scenario you can do your security handling for each child application within you.

      M 1 Reply Last reply
      0
      • L LongRange Shooter

        Major_A398 wrote:

        I'm looking for a way in C#.NET 2.0 to not allow my application from being closed by Task Manager by doing an End Task. Was thinking about displaying an error message saying you can't close this task. Any Ideas?

        On your parent form, implement a handler for the Closing event. The Closing EventArg allows you to set e.Cancel = true;

        Major_A398 wrote:

        Also I'm looking for a way to detect certain applications are started and not allow them to start with a message box that says something like "Not aloud to run this app".

        This would require unsafe code hooked into the WinAPI. Can't help you there. An alternative is to have all applications as MDI children and the controller is the MDIParent. In this scenario you can do your security handling for each child application within you.

        M Offline
        M Offline
        Major_A398
        wrote on last edited by
        #3

        I already have a Closing Event: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { this.Hide(); e.Cancel = true; } and when I do a Ctrl + Alt + Del then select the EXE and click end task it allows me to do this. As for the alternative what you are saying is have like a control panel / menu that has all the applications and they can launch them from there? What prevents someone from just going to c:\windows\system32\notepad.exe from the start --> run, or start --> Programs doing it this way?

        L 1 Reply Last reply
        0
        • M Major_A398

          I already have a Closing Event: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { this.Hide(); e.Cancel = true; } and when I do a Ctrl + Alt + Del then select the EXE and click end task it allows me to do this. As for the alternative what you are saying is have like a control panel / menu that has all the applications and they can launch them from there? What prevents someone from just going to c:\windows\system32\notepad.exe from the start --> run, or start --> Programs doing it this way?

          L Offline
          L Offline
          LongRange Shooter
          wrote on last edited by
          #4

          You can use ACL's to disallow users from running Task Manager to kill your application. When task manager kills a process, it KILLS the process.

          Major_A398 wrote:

          As for the alternative what you are saying is have like a control panel / menu that has all the applications and they can launch them from there?

          Well...actually you would have a controller for you application which is written as a Form and defined as an MDIParent. (Properties in the Windows.Form properties) It would present a menu or panel that lists application (actually you can control what gets listed in the menu by rights!!!) When the application is chosen from the menu it runs inside the MDIParent as one of its' children. This is similar to running the document editor instances in Word....except you are running all of the application instances. You would probably have to have each application implement an interface so that you can easily create an instance of each application and a consistant naming standard for the form that starts the application (like Main). A user would switch between the applications via the Window option in the Menu or would just tile the applications and pick the one they want. This also has an added benefit in that you can easily control which applications can be run as a single instance or multiple instances. Your application just changes by being defined as an MDIParent. And as I said in an earlier post, you would create an instance of each object, set yourself as the MDIParent, and then call the Show() method. The application is now an independant child inside your frame. All your applications get compiled as classes instead of as Windows applications. So they exist as DLL's in your library folder which prevents anyone from randomly running whatever they want. Use an external config file or a Resource file that defines an ID for each application and the namespace:assembly for each library. Then your code for launching is something like this: (I'm writing this by memory at home so don't take it as perfect, ready-to-compile:

          IApplication instance = (IApplication)Application.CreateInstance( manager.GetResource(appID) );
          runList.Add(instance); // make sure it does not get disposed
          instance.MDIParent = this;
          instance.Show();
          

          Have fun with it.

          M 1 Reply Last reply
          0
          • L LongRange Shooter

            You can use ACL's to disallow users from running Task Manager to kill your application. When task manager kills a process, it KILLS the process.

            Major_A398 wrote:

            As for the alternative what you are saying is have like a control panel / menu that has all the applications and they can launch them from there?

            Well...actually you would have a controller for you application which is written as a Form and defined as an MDIParent. (Properties in the Windows.Form properties) It would present a menu or panel that lists application (actually you can control what gets listed in the menu by rights!!!) When the application is chosen from the menu it runs inside the MDIParent as one of its' children. This is similar to running the document editor instances in Word....except you are running all of the application instances. You would probably have to have each application implement an interface so that you can easily create an instance of each application and a consistant naming standard for the form that starts the application (like Main). A user would switch between the applications via the Window option in the Menu or would just tile the applications and pick the one they want. This also has an added benefit in that you can easily control which applications can be run as a single instance or multiple instances. Your application just changes by being defined as an MDIParent. And as I said in an earlier post, you would create an instance of each object, set yourself as the MDIParent, and then call the Show() method. The application is now an independant child inside your frame. All your applications get compiled as classes instead of as Windows applications. So they exist as DLL's in your library folder which prevents anyone from randomly running whatever they want. Use an external config file or a Resource file that defines an ID for each application and the namespace:assembly for each library. Then your code for launching is something like this: (I'm writing this by memory at home so don't take it as perfect, ready-to-compile:

            IApplication instance = (IApplication)Application.CreateInstance( manager.GetResource(appID) );
            runList.Add(instance); // make sure it does not get disposed
            instance.MDIParent = this;
            instance.Show();
            

            Have fun with it.

            M Offline
            M Offline
            Major_A398
            wrote on last edited by
            #5

            theRealCondor wrote:

            You can use ACL's to disallow users from running Task Manager to kill your application. When task manager kills a process, it KILLS the process.

            There has to be another way to do this, as I have seen this with some other apps where you can't end task on the exe.

            theRealCondor wrote:

            Well...actually you would have a controller for you application which is written as a Form and defined as an MDIParent. (Properties in the Windows.Form properties) It would present a menu or panel that lists application (actually you can control what gets listed in the menu by rights!!!) When the application is chosen from the menu it runs inside the MDIParent as one of its' children. This is similar to running the document editor instances in Word....except you are running all of the application instances. You would probably have to have each application implement an interface so that you can easily create an instance of each application and a consistant naming standard for the form that starts the application (like Main). A user would switch between the applications via the Window option in the Menu or would just tile the applications and pick the one they want. This also has an added benefit in that you can easily control which applications can be run as a single instance or multiple instances. Your application just changes by being defined as an MDIParent. And as I said in an earlier post, you would create an instance of each object, set yourself as the MDIParent, and then call the Show() method. The application is now an independant child inside your frame. All your applications get compiled as classes instead of as Windows applications. So they exist as DLL's in your library folder which prevents anyone from randomly running whatever they want. Use an external config file or a Resource file that defines an ID for each application and the namespace:assembly for each library. Then your code for launching is something like this: (I'm writing this by memory at home so don't take it as perfect, ready-to-compile: IApplication instance = (IApplication)Application.CreateInstance( manager.GetResource(appID) ); runList.Add(instance); // make sure it does not get disposed instance.MDIParent = this; instance.Show(); Have fun with it.

            This isn't what I want to do at all. If someone launches Notepad.exe from where ever, start --> run notepad.exe, start -->

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups