WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check for multiple instances of an application

Keywords:  WinIdNameID multiple instances application

Question:

I want to check to see if a user, inadvertantly launched another instance of an application. I am aware that I can change the title of the window that my script launched by using WinTitle, and then check for any more instances of the original title and WinClose them. However, I do not like this approach because it is visible to users.

Do you have any other way to handle this problem?

Answer:

;DEFINE THESE VARIABLES
appname="app.exe"
windowname="Title"

Run(appname, "")
WinWaitExist(windowname,10)
;get main windows, window id
Mainid=WinIdGet(windowname);

;call this subroutine if you need to check for and shut down mulitple instances
gosub checkapps

;~~~~~~~~~~SUBROUTINE~~~~~~~~~~~~~~~
:checkapps
;activate window, so it will be first one found in WinItemNameid
WinActivate(mainid)

;get list of windowname and id's
list=WinItemNameId()

;how many windows + id's ?
count=Itemcount(list,"|")
;If there is more than one window found
if count > 2
  For xx=1 to count by 2
        ;gets window name
        thiswin=ItemExtract(xx,list,"|")
	;gets window id
        thisid=ItemExtract(xx+1,list,"|")
	;message(thiswin,thisid);debugging
	;search for windowname
	if strindex(thiswin,windowname,0,@FWDSCAN)
	  ;make sure your not closing the main window
	  if thisid != mainid
	    WinClose(Thisid)
	  endif
	endif
  Next
Endif
return


Article ID:   W13137
Filename:   Check for multiple instances of an application.txt
File Created: 1999:04:15:16:52:00
Last Updated: 1999:04:15:16:52:00