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. How to open only one instance of an application?

How to open only one instance of an application?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpasp-netvisual-studiotools
4 Posts 2 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.
  • J Offline
    J Offline
    just3ala2
    wrote on last edited by
    #1

    Dear all, i'm an ASp.net developer but i'm workin on a desktop application There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message So how can i know that there is an instance already running? One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory. Any key how can i implement that? P.S. I'm using VB script on VS.net 2003

    Best Regards 3ala2 :)

    J S 2 Replies Last reply
    0
    • J just3ala2

      Dear all, i'm an ASp.net developer but i'm workin on a desktop application There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message So how can i know that there is an instance already running? One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory. Any key how can i implement that? P.S. I'm using VB script on VS.net 2003

      Best Regards 3ala2 :)

      J Offline
      J Offline
      just3ala2
      wrote on last edited by
      #2

      I found the solution :D It's by importing: System.Diagnostics declaring a process array and use the GetProcess method then looping throught the array and check if the process already exists... Thanks anyway

      Best Regards 3ala2 :)

      1 Reply Last reply
      0
      • J just3ala2

        Dear all, i'm an ASp.net developer but i'm workin on a desktop application There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message So how can i know that there is an instance already running? One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory. Any key how can i implement that? P.S. I'm using VB script on VS.net 2003

        Best Regards 3ala2 :)

        S Offline
        S Offline
        Steven J Jowett
        wrote on last edited by
        #3

        Try this :- Dim currentProcess As Process = Process.GetCurrentProcess() Dim allProcesses() As Process = Process.GetProcessesByName(currentProcess.ProcessName) If allProcesses.Length > 1 Then Me.Opacity = 0.5 MessageBox.Show("Program already running. This session will close") Application.Exit() End If

        Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

        J 1 Reply Last reply
        0
        • S Steven J Jowett

          Try this :- Dim currentProcess As Process = Process.GetCurrentProcess() Dim allProcesses() As Process = Process.GetProcessesByName(currentProcess.ProcessName) If allProcesses.Length > 1 Then Me.Opacity = 0.5 MessageBox.Show("Program already running. This session will close") Application.Exit() End If

          Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

          J Offline
          J Offline
          just3ala2
          wrote on last edited by
          #4

          Thank u very much :-D I tired it and it works great Thanx again

          Best Regards 3ala2 :)

          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