Processes: Starting, Tracking, and stopping articles

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
i already know you can start new processes (IE) like this:

System.Diagnostics.Process.Start("IExplore", "http://www.WebSite.com")

but i'm looking for good articles on how to start that process and let it run for 5mins then close the catch is i need to track it so it only closes the ONE it opened not all the IE windows is this possible? thanx guys

i wouldnt mind code either, but i'd prefer articles explaining it, thanx
 
Ok I found a helpful thread on another forum (i dont have a link sry) but here i can now close all the IE windows, any idea's on how ta close just the one that vb opened? any books or anything?

VB.NET:
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System.ComponentModel

Private Sub KillProcess(byval ProcessName as string)
        Dim prc() As Process
        Dim ERROR_FILE_NOT_FOUND As Integer = 2
        Dim ERROR_ACCESS_DENIED As Integer = 5
        Try
            prc = System.Diagnostics.Process.GetProcessesByName("ProcessName")
            Dim eprc As IEnumerator = prc.GetEnumerator
            eprc.Reset()

            While eprc.MoveNext
                Dim proc As Process = CType(eprc.Current, Process)
                proc.Kill()
                proc = Nothing
            End While

            eprc = Nothing
            prc = Nothing

        Catch e As Win32Exception
            If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
                MessageBox.Show(e.Message + ". Process not found.")

            Else
                If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
                    ' Note that if your word processor might generate exceptions 
                    ' such as this, which are handled first. 
                    MessageBox.Show(e.Message + ". You do not have permission to kill this process.")
                End If
            End If
        End Try
    End Sub
 
Last edited:
Back
Top