|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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
|
|
#5
|
|||
|
|||
|
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.. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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...)
|
|
#8
|
|||
|
|||
|
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. |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
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.








Linear Mode

