tags:

views:

771

answers:

11

I've got a Visual Basic App that tends to get severely messed up if the installation runs more than once. It seems the occasionally client mistakes the installer for the shortcut to it later on down the road, runs the installer again and it messes everything up. I can't for the life of me figure out why so I decided the easiest way would be to make it so the exe could only be run once on a machine otherwise it would just end. Any ideas?

+1  A: 

Have your installer place a file in the applications folder.

When runs again, check for that file, if it exists, display a "Already installed" popup and exit.

FlySwat
What if the user deletes the file manually?
eyelidlessness
And what if the program Crash...
Daok
Then that user deserves a broken program
FlySwat
You install the marker file last, and you can name it DONOTDELETE.ME or something if you're concerned about users who probably don't belong anywhere near the Program Files folder... Alternatively you can check the registry to see if there is a standard uninstall entry for your app (Add/Remove Progs)
TheXenocide
+1  A: 

You could have the installer EXE file delete itself, well not directly while it's running but pass off a call to another service to delete it after it's done running.

I thought this was interesting so I Googled it, seems like some good info on this post:

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

shogun
+2  A: 

Assuming this is a VB6 question, you can use the built in App.PrevInstance.

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

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

In your Startup Form's load event or your 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 go one step further and bring the previous instance to the foreground, 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

Shane
Missed the point of the question. Its how to run once ever, not one at a time. (Not that running once ever is the solution to the OPs real problem)
Steve Fallows
A: 

If you are using VB.NET with Visual Studio 2005 or 2008 you can check the 'Make Single Instance Application' option in the Windows Application Framework section of the Application tab in the project settings.

Rob Windsor
Missed the point of the question. Its how to run once ever, not one at a time. (Not that running once ever is the solution to the OPs real problem)
Steve Fallows
A: 

Maybe checking the running processes on the machine to tell you if another instance exists would help? See this thread for more info...

ZombieSheep
Missed the point of the question. Its how to run once ever, not one at a time. (Not that running once ever is the solution to the OPs real problem).
Steve Fallows
+1  A: 

If you are using .net then Mutex's are your friend here.

Never, ever use the Process.GetProcessesByName method. You'll only hate yourself later for using 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;    
      }
}
mutexes are no use - he does not mean concurrent instances.
Tim
+1  A: 

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

Exactly how to achieve this will depend on the installer technology that you are using.

Kramii
+6  A: 

Why don't you FIX the installer or whatever problems are happening rather than try to make some hack to avoid it...

Just my $.02

Tim
+1  A: 

On the installer app

' 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

On the uninstaller app (or the "uninstall" option of the installer)

' Allow future Installer to run again
Call DeleteSetting("MyInstallerApp", "Startup")
jpinto3912
A: 

It strikes me that leaving an application around that shouldn't be run more than once is like leaving a big red button somewhere in someone's desk, that when pushed blows up the desk. Not cool.

Most installers have a feature to not offer repeat installation. Check that first - that seems like the best, most obvious solution.

What is severely messed up? How is running the installer a second time different from running it the first from your application's point of view? That should be addressed in your code as well.

plinth
A: 

You could check and see if the installed application files already exist. Assuming that is, you know where the application was installed to.

Jonathan Swift