Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Already Running

How can I check if there is already an instance of my VB.NET 2003 application already running?
0
SETP
Asked:
SETP
1 Solution
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now