Sinisterly
[VB.Net] [Snippet] Anti-unwanted Process - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.Net] [Snippet] Anti-unwanted Process (/Thread-VB-Net-Snippet-Anti-unwanted-Process)



[VB.Net] [Snippet] Anti-unwanted Process - Coder-san - 04-03-2011

Code:
Dim AntiProcess() As String = {"notepad", "mspaint", "taskmgr"} 'etc
            For intI As Integer = 0 To AntiProcess.GetUpperBound(0)
                'Dim procFound As Integer = Process.GetProcessesByName(AntiProcess(intI)).Length
                For Each x As Process In Process.GetProcessesByName(AntiProcess(intI))
                    x.CloseMainWindow() 'or x.Kill()
                Next
                'If procFound > 0 Then End
            Next

This will send close message / end all the Process (even multiple instances) in the AntiProcess() if they are not locked or have some other cool security.


RE: [VB.Net] [Snippet] Anti-unwanted Process - Coder-san - 04-03-2011

Credits to [link=http://www.windowsitpro.com/article/registry2/how-can-i-stop-and-start-services-from-the-command-line-.aspx]WindowsITpro[/link]

Code:
Shell("net stop servicename")

Shell("net stop superfetch") 'example



RE: [VB.Net] [Snippet] Anti-unwanted Process - Coder-san - 04-03-2011

I'm not sure, but it works. Just takes a few seconds.


RE: [VB.Net] [Snippet] Anti-unwanted Process - nosferatus - 04-04-2011

Thank you for the snippet.
Tested and working great.
What is even more great, is you can add a timer and make it check if any of the apps is running at all time.

Code:
Public Class Form1
    Sub protect()
        Dim AntiProcess() As String = {"notepad", "mspaint", "taskmgr"} 'etc
        For intI As Integer = 0 To AntiProcess.GetUpperBound(0)
            'Dim procFound As Integer = Process.GetProcessesByName(AntiProcess(intI)).Length
            For Each x As Process In Process.GetProcessesByName(AntiProcess(intI))
                x.CloseMainWindow() 'or x.Kill()
            Next
            'If procFound > 0 Then End
        Next
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        protect()

    End Sub
End Class