Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB.NEt instance checking app

VB.NEt instance checking app

Scheduled Pinned Locked Moved Visual Basic
csharpquestionlearning
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TeleT3ch
    wrote on last edited by
    #1

    I am trying to figure out if VB.NET (or even VB6) is the best way to test for an existing instance of an application. Basically, I want the code to test (I assume in Processes) whether the application is already active, and if it is, not open a second instance. (Of course, if it is not already running, then the application should open). Can anyone steer me in the right direction?

    C 1 Reply Last reply
    0
    • T TeleT3ch

      I am trying to figure out if VB.NET (or even VB6) is the best way to test for an existing instance of an application. Basically, I want the code to test (I assume in Processes) whether the application is already active, and if it is, not open a second instance. (Of course, if it is not already running, then the application should open). Can anyone steer me in the right direction?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Your application should do this, not some external application. The way you've worded this suggests that you think otherwise. No, C++ is the best language to do this in, but if you're stuck with VB.NET, then there's no reason why VB.NET can't do it. There are tons of examples on the web, and probably even on CP. You're more likely to find them in C#, I'd have thought, but they should be easy to convert. I have no doubt that this is beyond VB6's meagre abilities. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      T 1 Reply Last reply
      0
      • C Christian Graus

        Your application should do this, not some external application. The way you've worded this suggests that you think otherwise. No, C++ is the best language to do this in, but if you're stuck with VB.NET, then there's no reason why VB.NET can't do it. There are tons of examples on the web, and probably even on CP. You're more likely to find them in C#, I'd have thought, but they should be easy to convert. I have no doubt that this is beyond VB6's meagre abilities. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

        T Offline
        T Offline
        TeleT3ch
        wrote on last edited by
        #3

        Yes, the base application should do this...long story as to why it doesn't. Anyway, VB.NET is what I'm "stuck with" to achieve this objective. Can you point me to some examples "on the web" and/or CodeProject? Thanks!

        R 1 Reply Last reply
        0
        • T TeleT3ch

          Yes, the base application should do this...long story as to why it doesn't. Anyway, VB.NET is what I'm "stuck with" to achieve this objective. Can you point me to some examples "on the web" and/or CodeProject? Thanks!

          R Offline
          R Offline
          rwestgraham
          wrote on last edited by
          #4

          You can do this with API calls, which are even within the grasp of VB6 "meager" abilities. LOL. EnumProcesses is one way but it can be cumbersome to work with. If the application creates a main window that has a reasonably unique caption that does not change (in other words, this would never work with a web browser, but is feasible for most regular compiled apps) you can use the FindWindowEx API. If you search for the app caption and window class, and the handle returns as zero, the app is (probably) not running. Use Spy to help you determine the caption and window class name to search for. Robert

          T 1 Reply Last reply
          0
          • R rwestgraham

            You can do this with API calls, which are even within the grasp of VB6 "meager" abilities. LOL. EnumProcesses is one way but it can be cumbersome to work with. If the application creates a main window that has a reasonably unique caption that does not change (in other words, this would never work with a web browser, but is feasible for most regular compiled apps) you can use the FindWindowEx API. If you search for the app caption and window class, and the handle returns as zero, the app is (probably) not running. Use Spy to help you determine the caption and window class name to search for. Robert

            T Offline
            T Offline
            TeleT3ch
            wrote on last edited by
            #5

            Robert, Thank you for the information. I am not familiar with the type of calls you are referring to. Could you provide a code example to accomplish what you are describing? Thanks!

            I 1 Reply Last reply
            0
            • T TeleT3ch

              Robert, Thank you for the information. I am not familiar with the type of calls you are referring to. Could you provide a code example to accomplish what you are describing? Thanks!

              I Offline
              I Offline
              Icharus
              wrote on last edited by
              #6

              Here is a quick and dirty way of checking for a process. First you need a reference to the SystemDiagnostics. Imports System.Diagnostics Then Dim myProcess As Process() = Process.GetProcessesByName("ProcessName") If myProcess.Length > 1 Then MsgBox("You can only have one instance of this application running.") End If Hope this helps :-)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups