Resolved Help needed with auto-killing of process

jojofromjory

Member
Joined
Sep 3, 2009
Messages
10
Programming Experience
1-3
Hello, I know this is my first post ever on this forum but I'm not a leecher, I'm here to help people but first I'd like to have some help myself, I'm creating an app in VB2008 that needs a function that automaticly closes the processes "iexplore.exe" and "firefox.exe".
Can anyone help me?

Greetz, Jojo
 
Last edited:
VB.NET:
        [COLOR="SeaGreen"]'Itterate thru all running processes[/COLOR]
        [COLOR="blue"]For Each [/COLOR]proc [COLOR="blue"]As [/COLOR]Process [COLOR="blue"]In [/COLOR]Process.GetProcesses
            [COLOR="seagreen"]'Check to see if its the program you want to close ie: "iexplore"[/COLOR]
            [COLOR="blue"]If [/COLOR]proc.ProcessName.ToLower = "notepad" [COLOR="blue"]Then[/COLOR]
                [COLOR="seagreen"]'Close process by sending a close message to its main window[/COLOR]
                proc.CloseMainWindow()

                [COLOR="seagreen"]'Free resources associated with process[/COLOR]
                proc.Close()
            [COLOR="blue"]End If[/COLOR]
        [COLOR="blue"]Next[/COLOR]
 
VB.NET:
        [COLOR="SeaGreen"]'Itterate thru all running processes[/COLOR]
        [COLOR="blue"]For Each [/COLOR]proc [COLOR="blue"]As [/COLOR]Process [COLOR="blue"]In [/COLOR]Process.GetProcesses
            [COLOR="seagreen"]'Check to see if its the program you want to close ie: "iexplore"[/COLOR]
            [COLOR="blue"]If [/COLOR]proc.ProcessName.ToLower = "notepad" [COLOR="blue"]Then[/COLOR]
                [COLOR="seagreen"]'Close process by sending a close message to its main window[/COLOR]
                proc.CloseMainWindow()

                [COLOR="seagreen"]'Free resources associated with process[/COLOR]
                proc.Close()
            [COLOR="blue"]End If[/COLOR]
        [COLOR="blue"]Next[/COLOR]

Hey, I did everything u said but I don't know where to insert it, I'm making a webbrowser, isn't there a function that can check about every 5 seconds if there are none of the processes opened? I now have:
VB.NET:
'Itterate thru all running processes
        For Each proc As Process In Process.GetProcesses
            'Check to see if its the program you want to close ie: "iexplore"
            If proc.ProcessName.ToLower = "iexplore.exe" Then
                'Close process by sending a close message to its main window
                proc.CloseMainWindow()

                'Free resources associated with process
                proc.Close()
            End If
        Next
        'Itterate thru all running processes
        For Each proc As Process In Process.GetProcesses
            'Check to see if its the program you want to close ie: "iexplore"
            If proc.ProcessName.ToLower = "safari.exe" Then
                'Close process by sending a close message to its main window
                proc.CloseMainWindow()

                'Free resources associated with process
                proc.Close()
            End If
        Next
        'Itterate thru all running processes
        For Each proc As Process In Process.GetProcesses
            'Check to see if its the program you want to close ie: "iexplore"
            If proc.ProcessName.ToLower = "opera.exe" Then
                'Close process by sending a close message to its main window
                proc.CloseMainWindow()

                'Free resources associated with process
                proc.Close()
            End If
        Next
        'Itterate thru all running processes
        For Each proc As Process In Process.GetProcesses
            'Check to see if its the program you want to close ie: "iexplore"
            If proc.ProcessName.ToLower = "firefox.exe" Then
                'Close process by sending a close message to its main window
                proc.CloseMainWindow()

                'Free resources associated with process
                proc.Close()
            End If
        Next
 
First of all, you do not have to loop thru all the processes 4 times. Think of how to change the if statement to only loop through everything once. (if ya still need help, I will give ya the answer but better if you try to figure it out yourself first)

You can create a time and have it activate every 5 seconds but that would be very inefficient to have something constantly running in the background. Are you sure need to check that often?
 
I just do
VB.NET:
"firefox.exe" Or "iexplore.exe" Or "Safari.exe" Or "Opera.exe"
?
Also, I'm making a browser that disables all those processes every time when it's loaded so that it's not possible to open them within the time of program activation.

Greetz, Jojo
 
.exe is not needed

VB.NET:
        For Each proc As Process In Process.GetProcesses
            Select Case proc.ProcessName
                Case "iexplore", "safari", "firefox"
                    proc.CloseMainWindow()
                    proc.Close()
                Case Else
                    'do nothing
            End Select
        Next proc
 
Hey, I made a little addition with a 5 seconds timer running:
VB.NET:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For Each proc As Process In Process.GetProcesses
            Select Case proc.ProcessName
                Case "iexplore", "safari", "firefox", "opera"
                    proc.CloseMainWindow()
                    proc.Close()
                Case Else
                    'do nothing
            End Select
        Next proc
        Timer1.Enabled = True


    End Sub
Problem Solved!!
Ty for the help.

Greetz, Jojo
 
Why are you enabling the timer within the timer? In order to get into the event, it must already be enabled
 
Back
Top