VB Question

Steve Meisel

Member
Join Date
Jun 2002
Location
NC
Posts
77
Is there a way with VB6 to have the application check to see if there is another occurrance of the same application running?

We have several machines that are pc control, from VB, and when there are two of the same applications running strange things happen. Mostly the machine crashes and I stay busy for the next couple of hours.o_O
I have talked to the programmer (outside contractor) but he is not sure how to make the check. Any ideas?

Thanks,

Steve
 
You need to get the handle (hwnd) of the the window. This gives you the name of the app. This is what you see now in the very top left of your screen. You then do a for-next-loop and compare any new application starting against existing windows opened and automatically close the app if it matches something already running.
You start this through a splash screen first and then load the main window.
There are examples on the VB sites showing how this is done.

Has your programmmer ever heard of a google search?

http://www.developerfusion.co.uk/show/134/

If the link this doesn't help him, PM me later on today and I will post some of my own code which by the way I got off the net.
 
unsunghippie said:
Try This.

PrivateSub Form_Load()

If (App.PrevInstance = True) Then

MsgBox "Application already running"

Call someProcedure
EndIf


Its not that simple ( to be foolproof)
you need to find the handle , define a mutex class and then use it in the main form (??!!) and you need to close your ( second) apps before any damage is done.

look at : http://faq.vb.free.fr/index.php?question=46 ( I know its in french , so what ,the code is in 'VB')

or at : http://www.xtremevbtalk.com/showthread.php?t=129256

if you type 'mutex VB6 application running' in google you'll have enough examples

Eric
 
This has migrated off the PLC topic, but I don't understand why this would not be foolproof. If this code is placed as the first code in the startup form, and if someProcedure exits the app, the app should detect itself already running, and do nothing but display a message box, call the someProcedure and close. No harm, no foul. Remember, this is VB6 not .NET.

If I am missing something here, I am eager to learn.
 
Last edited:
unsunghippie said:
This has migrated off the PLC topic, but I don't understand why this would not be foolproof. If this code is placed as the first code in the startup form, and if someProcedure exits the app, the app should detect itself already running, and do nothing but display a message box, call the someProcedure and close. No harm, no foul. Remember, this is VB6 not .NET.

If I am missing something here, I am eager to learn.

Well I wrote some apps in Delphi with a 'check for apps allready running' and it worked ... on the develoment PC but not ( allways) on the user PC's ... did thid did that etc but eventualy this mutex beast does the trick everytime ( well at leadt on Win2000 and XP) .Maybe there are sublte ( microsoft) diferences between coding in VB or Delphi but looking at the net , I think that there is no easy solution.

Greeting

Eric
 
aikona said:
Well I wrote some apps in Delphi with a 'check for apps allready running' and it worked ... on the develoment PC but not ( allways) on the user PC's ... did thid(this) did that etc but eventualy this mutex beast does the trick everytime ( well at leadt(Least) on Win2000 and XP) .Maybe there are sublte(got a problem with this one)( microsoft) differences between coding in VB or Delphi but looking at the net , I think that there is no easy solution.

Greeting

Eric
Oops - sorry for all the spelling errors - no wonder my code never works
 
I had a look.
It only does not work if you are running a copy of the exe file in another folder, or a copy with a different name in the same folder.
Given that is hardly seems worth the trouble of the API methods.
Francis
 

Similar Topics

Hello again..trying something on an existing poorly written program and just wanted to double check something system is an A-B MicroLogix 1200 In...
Replies
5
Views
159
Good morning! Let me start by saying, I am still learning about this type of HMI programming. I recently watched a video about recipes and how it...
Replies
0
Views
62
I have some logic that I have written within a 5380 series controller that tracks the time an event is started, while the event is running an RTO...
Replies
2
Views
87
I have an HMI 2711R - T4T Series B, and I want to know which PLCs, besides Micro 820, can communicate with it.
Replies
2
Views
80
HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
75
Back
Top Bottom