Indigo Rose Software
  #1  
Old 10-19-2004
SUF6NEWBIE
Guest
 
Posts: n/a
Multi Instance at runtime Handler code

Here's an 'unrefined' ..could do with some Guru Help-refinement..

This is really just an adaptation of BRETTS example script.

Global Function to detect if 'mysetup' is already running and if so Exit.

function FindAndCloseProcessByName(strName, strnum)
local tblProcesses = Window.EnumerateProcesses(true);
local bProcessFound = false;
local nProccess = 0; --set intitial count to zero
local nProcessHandle = nil;
if(tblProcesses)then
local strProcessName;
local nHandle;
for nHandle, strProcessName in tblProcesses do
if(String.Find(strProcessName, strName, 1, false) ~= -1)then
nProcessHandle = nHandle;
nProccess = nProccess + 1;
bProcessFound = true;
end
end
end
if(bProcessFound and nProcessHandle)then
Dialog.Message("Total tgt Proccess", nProccess); --debug dialog only
if (nProccess >= strnum) then
Application.Exit(0); -- multi instance of mysetup detected so exit now
else
Window.Close(nProcessHandle,CLOSEWND_SENDMESSAGE);
end

end
end

to call it ..say in Startup actions...

FindAndCloseProcessByName("irsetup.exe", 2); -- Close App if 'irsetup' count > 1

Could others please check this out ...
(note - still can handle other proccess detection if called appropriately)
sorry about the 'layout' as displayed ...

tks

Last edited by SUF6NEWBIE; 10-19-2004 at 04:35 AM.
Reply With Quote
  #2  
Old 10-19-2004
SUF6NEWBIE
Guest
 
Posts: n/a
OOPS ! Change-remove the lines:

else
Window.Close(nProcessHandle,CLOSEWND_SENDMESSAGE);
end

to just:

end



I can see a 'limitation' ?..when a 'Dependancy Module' is part of 'mysetup'

the 'module script' runs Before any Global functions and Startup Actions.

I 'spose the Function could be included in the 'Detection Script' for a Module
as a way around this.

Last edited by SUF6NEWBIE; 10-19-2004 at 04:51 AM.
Reply With Quote
  #3  
Old 10-19-2004
SUF6NEWBIE
Guest
 
Posts: n/a
Here's a trimmed down test project you can use...
has the code ready to go upon build...

..should not alter your system..only a welcome screen and
a 'finish screen' ..no log files etc etc.
Attached Files
File Type: zip TestMultiInstanceB1.zip (5.8 KB, 15 views)
Reply With Quote
  #4  
Old 10-19-2004
csd214 csd214 is offline
Forum Member
 
Join Date: Oct 2001
Location: Norway
Posts: 939
SUF6NEWBIE, thanks for sharing your global script.

I encourage all SUF70 users to contribute to this forum LIKE THE AMS50 USERS DO. To really learn SUF70 you need:

1) The Help doc
2) Corey's Video Training CD
3) This Forum

The last element requires that the users participate with an open mind. I don't forget a function I published in the AMS Forum. It was a script with 44 lines (it worked and I was proud of it). Then Lorne stepped in and showed another way to do it: A script with 5 lines!! Don't miss the possibility to learn something new every day!

My contribution is a global script similar to SUF6NEWBIE'S, but I use the Windows Enumerate function and the session variable %ProductName%")

Code:
function CloseAppIfRuning(cpTitle)
--[[
function:	CloseAppIfRuning()
Purpose:	Stop runing the app if it is already started
Arguments:	Window Title as SessionVar.Get("%ProductName%")
Returns:	Nothing ::: CLOSES THE APP :::
Usage:	CloseAppIfRuning(SessionVar.Get("%ProductName%")); (in 'On Startup')
]]

	local tTitles = Window.EnumerateTitles(true); local bAppInUse = false; local nAppCount = 0;
	for nfHandle, cfEnumTitle in tTitles do
		if String.Find(cfEnumTitle, cpTitle, 1, false) ~= -1 then
			nAppCount = nAppCount + 1;
			if nAppCount > 1 then
				bAppInUse = true;
			end
		end
	end
	if bAppInUse then
		Dialog.Message("Error: In Use", "The application "..cpTitle.." is already started"
		.."\r\nThis second occurrence will now be terminated", MB_OK, MB_ICONSTOP);
		Application.Exit();
	end
end
Reply With Quote
  #5  
Old 10-19-2004
SUF6NEWBIE
Guest
 
Posts: n/a
TKS CSD...the enumerate title is more like how I do it in AMS

also thought I would have a crack at the 'proccess way'

Yep the more we share the more we can learn from each other.

I'll fire up your code and give it a run..
Reply With Quote
  #6  
Old 10-19-2004
SUF6NEWBIE
Guest
 
Posts: n/a
CSD ...found the Code you posted to be a little faster and solves
issues surrounding other 'irsetup.exe" that may purposefully
be running..as only detects by Product Name.

Another CSD triumph !

tks
Reply With Quote
  #7  
Old 10-20-2004
csd214 csd214 is offline
Forum Member
 
Join Date: Oct 2001
Location: Norway
Posts: 939
Thx for the credit (I have to confess: I'm a bit unsure about the process stuff; I feel more comfortable with closing the app by the window title...)
Reply With Quote
  #8  
Old 10-20-2004
SUF6NEWBIE
Guest
 
Posts: n/a
Doing things the 'proccess way' is limited in the area that
SUF7 and AMS5 rely on 'window integer id' and Not the actual
'proccess id' ..(which is the OS way of doing things.)

eG: a window.close action will often close the windows, however
the actual target proccess is not 'released' by the OS, is in reality
still 'running in the background'. windows.close 'terminate' will often 'kill'
the process, however any created files or runtime files must be
manually deleted etc.

This could be viewed as a 'limitation in proccesss handling' - 'window id'

to fully 'kill' -release some proccesses an external resource is still required.
(again any created files etc must be manually deleted)

Controlling 'open Windows' etc using SUF7 actions etc is still powerfull
and very usefull, the more I get 'down and dirty' with it all.

Last edited by SUF6NEWBIE; 10-20-2004 at 10:13 PM.
Reply With Quote
Reply

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Article: Using Authenticode Code Signing Certificates Ted Sullivan Setup Factory 8.0 Examples 4 10-31-2007 10:03 AM
Kill Multi Instances at Install Runtime SUF6NEWBIE Setup Factory 6.0 2 03-16-2004 06:27 PM
INFO: Microsoft Data Access Components 2.8 Runtime Notes Desmond Setup Factory 6.0 Knowledge Base 0 11-28-2003 09:20 AM
INFO: Visual C++ 6.0 (SP4) Runtime Support Module Support Setup Factory 6.0 Knowledge Base 0 10-30-2002 01:53 PM
INFO: MDAC 2.7 Runtime Support Module Support Setup Factory 6.0 Knowledge Base 0 10-17-2002 04:55 PM


All times are GMT -6. The time now is 10:15 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software