The best way to make exe run only once

I have a Visual Basic application that tends to be heavily overloaded if the installation is performed more than once. It seems that from time to time the client makes a mistake with the installer for quick access later on the road, the installer starts again, and it ruins everything. I cannot understand for life why I decided that the easiest way would be to make exe run only once on the machine, otherwise it would just end. Any ideas?

+6
vb6
source share
11 answers

Why don't you fix the installer or any problems, and not try to do some hacks to avoid this ...

Just my $ .02

+6
source share

Ask the installer to place the file in the application folder.

When you restart, check this file, if it exists, display the "Already installed" pop-up window and exit.

+3
source share

Assuming this is a VB6 issue, you can use the built-in App.PrevInstance application.

Documentation: http://msdn.microsoft.com/en-us/library/aa268085(VS.60).aspx

App.Previnstance returns True if your application is already running.

In the Startup Form boot event or in the Sub Main:

Private Sub Form_Load() If App.PrevInstance = True Then MsgBox "Already running" 'Do whatever you need to do before closing End If End Sub 

If you want to take another step and bring the previous instance to the fore, you can check out these articles:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=21131&lngWId=1

http://support.microsoft.com/kb/185730

+2
source share

You may have an installer .exe file that will delete itself, but not immediately while it is running, but pass the call to another service to delete it after it is executed.

I thought it was interesting, so I googled this seems to be good info on this post:

http://www.autohotkey.com/forum/topic1572.html

+1
source share

If you use .net, then Mutex is your friend here.

Never, never use the Process.GetProcessesByName method. You will only hate yourself later to use something that requires admin priviliges

 private bool CanIStart { try { MyAppMutex= new Mutex(false, "myAppMutex", out createdNew); if(MyAppMutex.WaitOne(0,false)) { return true; } else { MyAppMutex = null; return false; } } catch(ApplicationException ex) { // we couldn't create the mutex. // log the error if you care return false; } } 
+1
source share

Ask the installer to create a registry entry. Refuse to install (again) if a registry entry already exists.

Exactly how to achieve this will depend on the installer technology you use.

+1
source share

In the application to install

 ' Test eventual mark, settings in the registry. if GetSetting("MyInstallerApp","Startup","BeenHere",0) = 1 then MsgBox "This installer was ran once already... first run the un-installer." End ' or some other code to properly exit the installer EndIf Call SaveSetting ("MyInstallerApp","Startup", "BeenHere", 1) 'leave a mark for future 

In an uninstaller application (or the β€œuninstall” installer option)

 ' Allow future Installer to run again Call DeleteSetting("MyInstallerApp", "Startup") 
+1
source share

If you use VB.NET with Visual Studio 2005 or 2008, you can check the "Make a single-instance application" option in the "Windows Application View" section of the "Application" tab in the project settings.

0
source share

Maybe checking running processes on a computer to tell you if another instance would be useful? See this thread for more information ...

0
source share

It seems to me that leaving the application around, which should not be launched more than once, is like leaving a big red button somewhere in some table, which, when pushed, blew up the table. Not cool.

Most installers have a feature that does not offer reinstallation. First check that this seems like the best, most obvious solution.

What is bad? How to run the installer a second time, different from running it from the point of view of your application? This should also be considered in your code.

0
source share

You can check and check if already installed application files exist. Assuming you know where the application was installed.

0
source share

All Articles