Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check?
Previous and current version instance check? Previous and current version instance check?
Previous and current version instance check?
Go Back  Xtreme Visual Basic Talk > > > Previous and current version instance check?


Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2003, 08:24 PM
bkbig bkbig is offline
Freshman
 
Join Date: Dec 2002
Posts: 28
Question Previous and current version instance check?


How can I ensure that there is no previous or current version of my app currently open? I found in this forum that I could check for previous instance, but that doesn't include previous versions.

My app can currently be ran with multiple instances, each of which can be located in different directories. I want only one version of my app to run at any given time.

If I set a value in the registry, which I can use for all versions of my app, does the registry retain the value if Windows crashes and the user has to reboot?

Thanks for any help.

BK
__________________
still a newbie.
Reply With Quote
  #2  
Old 02-14-2003, 09:36 PM
Mr_Taneth Mr_Taneth is offline
Centurion
 
Join Date: Aug 2002
Posts: 109
Default

Yes Windows will retain the value if it crahes, unless the registry file gets corrupted when it crashes then it might be lossed.
Reply With Quote
  #3  
Old 02-15-2003, 05:52 AM
rimby rimby is offline
Junior Contributor
 
Join Date: Mar 2002
Posts: 372
Default

A better way would be to create a mutex for when your app starts and destroy the mutex when it ends. When your app starts up, it should check if the mutex is already in use (i.e. the app is already running), and if it is not, then it should create it and run normally.

The APIs CreateMutex and ReleaseMutex can be used to do this. Here is an example from the API Guide, entitled "Advanced PrevInstance":

Code:
'Code by Adam Verwijs Const ERROR_ALREADY_EXISTS = 183& Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As Any, ByVal bInitialOwner As Long, ByVal lpName As String) As Long Private Declare Function ReleaseMutex Lib "kernel32" (ByVal hMutex As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Sub Form_Load() Dim hMutex As Long 'Try to create a new Mutex hMutex = CreateMutex(ByVal 0&, 1, App.Title) 'Did the mutex already exist? If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then 'Clean up ReleaseMutex hMutex CloseHandle hMutex 'More than one instance detected MsgBox "More than one instance" End Else 'form load code End If End Sub
Reply With Quote
  #4  
Old 02-15-2003, 11:46 AM
bkbig bkbig is offline
Freshman
 
Join Date: Dec 2002
Posts: 28
Default

thanks for the help.

If Windows will retain it's registry values after a crash, and my app stores a value in the registry informing my program that an instance is running; after a crash, how will I be able to start another instance if the registry says there is already one running, and my app won't run if another instance running?

I'll check out the API call CreateMutex.
__________________
still a newbie.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check? Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check? Previous and current version instance check?
Previous and current version instance check?
Previous and current version instance check?
 
Previous and current version instance check?
Previous and current version instance check?
 
-->