Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27208

Need help with this code

$
0
0
I need to code in my program that when run, it kills some specific processes. In this example: notepad.exe, calc.exe and mspaint.exe

I found the code for this which is:
Code:

Dim taskmgr As Integer = 1

        Do Until taskmgr = 5

            Dim proc = Process.GetProcessesByName("notepad")
            For i As Integer = 0 To proc.Length - 1
                proc(i).CloseMainWindow()
            Next i


            taskmgr = taskmgr + 1

            If taskmgr = 5 Then
                taskmgr = 3
            End If

        Loop

(I added a Do until loop so the user would not be able to open them back manually)
That worked fine when i used the code for only one process.

When i added the same code again (with different variables of coarse) they did not work, only the first piece of code worked.

This is my current code:
Code:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim taskmgr As Integer = 1

        Do Until taskmgr = 5

            Dim proc = Process.GetProcessesByName("notepad")
            For i As Integer = 0 To proc.Length - 1
                proc(i).CloseMainWindow()
            Next i


            taskmgr = taskmgr + 1

            If taskmgr = 5 Then
                taskmgr = 3
            End If

        Loop

        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim cmd As Integer = 1

        Do Until cmd = 5

            Dim proc = Process.GetProcessesByName("mspaint.exe")
            For i As Integer = 0 To proc.Length - 1
                proc(i).CloseMainWindow()
            Next i


            cmd = cmd + 1

            If cmd = 5 Then
                cmd = 3
            End If

        Loop

        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim num As Integer = 1

        Do Until num = 5

            Dim proc = Process.GetProcessesByName("calc")
            For i As Integer = 0 To proc.Length - 1
                proc(i).CloseMainWindow()
            Next i


            num = num + 1

            If num = 5 Then
                num = 3
            End If

        Loop

        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    End Sub


End Class

So basically, only the process notepad.exe gets killed(because its the first piece of code), the other two don't for some reason.
I need to be able to kill 3 processes at once, not just one. Not sure what is wrong here. I am targeting .net framework 2.0.

Appreciate any help on how i can fix this, or maybe some different codes if these do not work.

Viewing all articles
Browse latest Browse all 27208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>