Already Running

How can I check if there is already an instance of my VB.NET 2003 application already running?
SETPAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
You can check to see if a copy of you program is already running by doing the following.

Imports System.Diagnostics

    Dim myProcess As Process = New Process
    Dim ProcessList() As Process

    ' Replace calc with the name of the program you are looking for without
    ' the .exe part.
    ProcessList = myProcess.GetProcessesByName("calc")
    If ProcessList Is Nothing Then
         ' There is no instance of the program
    Else
        ' Then ProcessList has an array of the number of copies that are running
    End If

I hope this was of some help
0
 
SETPAuthor Commented:
Thanks for both your answers, but I think Idle_Mind's solution will work and he was first, so...
0
 
Ramesh SrinivasTechnical ConsultantCommented:
Dim wmiobjset As Object
        Dim wmiservice As Object
        Dim wmiobj As Object
        Dim strComputer = "."

        wmiservice = GetObject("winmgmts://" & strComputer & "/root/cimv2")
        For Each wmiobj In wmiservice.InstancesOf("win32_process")
            If UCase(wmiobj.Name) = "NOTEPAD.EXE" Then
                MsgBox(wmiobj.Name)
            End If
        Next
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.