none
Prevent app from closing by Task Manager RRS feed

  • Question

  • Hi,

    I am writing an application for my personal use, which is an Auto system shutdown app.

    It will work in 2 ways, set some time from now, or set a time to shutdown in the future.

    Usage for me is vital, however when I Googled VB.NET prevent app from being closed by Task Manager I found disappointing answers!

    1st of all, I know it should need some Win32 coding, and no native VB.NET 2017 .NET FW 4.0 can do this.

    But most of the responses to this question was : What are you trying to do with this code snippet?

    This can be used for malware! or something similar!

    Censoring information and knowledge to prevent use it in a bad way is silly! Who writes such an evil application in VB.NET?

    Also we are not Judge ! To verdict the others ! If you don't know the answer, or simply don't want to give the response, please disregard the thread.I'm using VB.NET 2017 - .NET FW 4.0.

    My application should not be closed by my friends who use my PC after me, I found that this code DOES NOT WORK at all:

    Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    
    If e.CloseReason = CloseReason.TaskManagerClosing Then
        e.Cancel = True
        MessageBox.Show("Task manager tried to close me")
    End If
    
    End Sub


    Also, make the application name hidden from Task Manager list is also OK.

    I found that I also cannot close my McAfee process via Task Manager, so it should not be that bad!


    Friday, May 26, 2017 6:29 AM

All replies

  • Hi OSVBNET,

    Welcome to the MSDN forum.

    Refer to your description, your issue is about the VB development. Since our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum: Visual Studio Languages  >  Visual Basic to seek for a more professional support, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 29, 2017 2:01 AM
  •  The reason you find these kind of answers is because even if you do not have any intent on using the code maliciously,  there are millions of other people that can read this question which i will guarantee some would have a malicious intent.  No matter if it is Vb.Net,  C++,  or any other language,  malicious code can be written.

     Any respectable public forum you find will have rules about not answering questions which can be used maliciously.  You can find the thread linked below at the very top of this forum`s main page.

    Contributors: How to avoid aiding the development of malicious code


    If you say it can`t be done then i`ll try it

    • Proposed as answer by Cor Ligthert Monday, May 29, 2017 8:15 AM
    Monday, May 29, 2017 2:44 AM
  • Well, any idea why this code does not work?

    Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    If e.CloseReason = CloseReason.TaskManagerClosing Then MsgBox "Task Manager tried to close me!"

    Friday, June 16, 2017 2:54 PM
  • Hi

    It is a bit strange. If this application is only running on your computer then you have full control over who closes your application. You say your friends are not permitted to close it - then just tell them so.

    '

    Also, if you did manage to set up such an application, then how would you close it down? Maybe just switch off your computer?

    '

    I can not see any value in doing this.

    '

    There are very good reasons why such things are not easy to do, and to publish such things to the entire world is NOT a good idea.

    '

    Why no just intercept the Form Closing event (as you have said), and put in a routine to ask for a password for shut down. It wouldn't stop the taskmanager from closing it, but, if your friends wanted to use the taskmanager to close your application when they know you don't want it shut down - easy - get new friends.


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, June 16, 2017 3:19 PM
    Friday, June 16, 2017 3:18 PM
  • Why no just intercept the Form Closing event (as you have said), and put in a routine to ask for a password for shut down. It wouldn't stop the taskmanager from closing it, but, if your friends wanted to use the taskmanager to close your application when they know you don't want it shut down - easy - get new friends.

    Hey dude,

    This is exactly what I'm gonna accomplish!

    Get the password to shutdown the app, however, let's forget about everything, just the above simple which is very supposed to work is not working for my own Admin account!!!

    Friday, June 16, 2017 3:59 PM
  • Hey dude,

    This is exactly what I'm gonna accomplish!

    Get the password to shutdown the app, however, let's forget about everything, just the above simple which is very supposed to work is not working for my own Admin account!!!

    Hi

    Please show the code you are using for the Close event handler and any code to get/check a password. (change the real password to a dummy password for posting)


    Regards Les, Livingston, Scotland

    Friday, June 16, 2017 5:23 PM
  • Hi

    This seems to work OK - give it a try.

        Dim password As String = "MyPassWord"
        Function GetPassword() As Boolean
            If InputBox("Please enter you Password", "Enter Password", Nothing) = password Then
                Return True
            End If
            Return False
        End Function
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            ' case sensitive password
            If Not GetPassword() Then
                e.Cancel = True
                MessageBox.Show("You must use the correct password to shut down this application.")
                Exit Sub
            End If
        End Sub


    Regards Les, Livingston, Scotland

    Friday, June 16, 2017 5:45 PM
  • Dude, getting password on form closing is abcd, in addition to that, I need to get the password on form closing caused by Task Manager.

    And this very simple code for no reason does not work:

    Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    If e.CloseReason = CloseReason.TaskManagerClosing Then MsgBox "Task Manager tried to close me!"

    e.CloseReason = CloseReason.TaskManagerClosing is NOT something malicious, otherwise IT WAS NOT obviously in the Form Closing event controls...

    Friday, June 16, 2017 6:23 PM
  • Task Manager closing never sends the event message to the form, so you will have to do something else.

    Create a 2nd program to monitor the 1st program and restart it if it is not running.

    Create another program to monitor the first 2 programs and restart the ones that are not running.
    Create another program to monitor the first 3 programs and restart the ones that are not running.
    Create another program to monitor the first 4 programs and restart the ones that are not running.
    Create another program to monitor the first 5 programs and restart the ones that are not running.
    repeat that until:
    Create another program to monitor the first 10000 programs and restart the ones that are not running.



    Saturday, June 17, 2017 12:21 AM
  • Here's an interesting take on the quest for the Unkillable Program -

    The arms race between programs and users

    Saturday, June 17, 2017 2:20 AM
  • Here's an interesting take on the quest for the Unkillable Program -

    The arms race between programs and users

    Hi

    OSVBNET needs to read the content of that link.


    Regards Les, Livingston, Scotland

    Saturday, June 17, 2017 3:33 AM
  • Just an application that will fill the whole screen and it will force other app to go behind it. if their is a shortcut used to  activate them it will hind behind your application. because you want to get the password of your friends it will help.
    Wednesday, August 8, 2018 8:25 PM