Get Previous Instances : Process « Windows System « VB.Net






Get Previous Instances

    

Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Friend WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        Me.Label1.Location = New System.Drawing.Point(16, 16)
        Me.Label1.Size = New System.Drawing.Size(296, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Run the final .EXE version of this application."
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(360, 157)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1})
        Me.ResumeLayout(False)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If PrevInstance() = True Then
            Dim Processes() As Process
            Processes = Diagnostics.Process.GetProcessesByName( Diagnostics.Process.GetCurrentProcess.ProcessName)
            AppActivate(Processes(0).Id)
            Application.Exit()
        End If
    End Sub

    Public Function PrevInstance() As Boolean
        If Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName).Length > 1 Then
            Return True
        Else
            Return False
        End If
    End Function

End Class

   
    
    
    
  








Related examples in the same category

1.Check Existing Duplicate Process
2.Get current Running ProcessGet current Running Process
3.Use Process to Start IExplore.exe
4.Start a Process
5.Checking for a Previous Instance
6.Get the current process.
7.Get all instances of Notepad running on the local computer
8.Get all instances of Notepad running on the specifiec computer
9.Using an IP address to specify the machineName parameter
10.Get all processes running on the local computer
11.Get all processes running on the remote computer
12.Get a process on the local computer, using the process id
13.Get a process on a remote computer, using the process id
14.Process with arguments
15.Uses the ProcessStartInfo class to start new processes, both in a minimized mode.