Already Running

Posted on 2005-05-12
Last Modified: 2010-05-18
How can I check if there is already an instance of my VB.NET 2003 application already running?
Question by:SETP
    LVL 85

    Accepted Solution

    LVL 62

    Expert Comment

    by:Fernando Soto
    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
            ' Then ProcessList has an array of the number of copies that are running
        End If

    I hope this was of some help

    Author Comment

    Thanks for both your answers, but I think Idle_Mind's solution will work and he was first, so...
    LVL 11

    Expert Comment

    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
                End If

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now