View Full Version : Kiosk - prevent multiple launch of software?
doc13x
06-21-2007, 01:42 PM
Is there a way to have AMS6 determine if a program is already running, and then switch back to it if the user selects it again? I have set up a kiosk project with several different software shortcuts - launching several copies of the same software (through the kiosk screen) is causing problems.
Centauri Soldier
06-23-2007, 10:40 AM
open_processes = Window.EnumerateProcesses();
This will determine what processes are running and give you their window handles. Can simply pull them forward or send them back (or minimize/maximaize) using that number.
If, for instance you had a process running with an associated handle of ec_handle you could...
Window.Show(ec_handle);
Hope that helps
Here's the code I use. What I do here is save the window handle of the kiosk app to the registry everytime the app is launched. As a precondition to that action, I check to see if the handle of my app matches the last one that was saved to the registry and if so, kill the new instance.
This code goes in the "Global Functions" event for your project then call the IsKioskRunning() action on the "On Startup" event.
function IsKioskRunning()
-- Initialize your variables
g_Return = false;
g_RegSection = "MyKioskApp";
g_RegKey = "KioskHandle";
t_Processes = {};
-- Load the previous handle from the registry if there is one
g_LastHandle = Application.LoadValue(g_RegSection, g_RegKey);
-- Check to see if the loaded value is blank
if g_LastHandle ~= "" then
-- If not, table out all of the current processes
t_Processes = Window.EnumerateProcesses(false);
-- Compare the window handle of each to the value from the registry
for g_WindowHandle, g_ProcessName in t_Processes do
-- If found, set the return variable to true
if g_WindowHandle == g_LastHandle then
Application.Exit();
end
end
end
-- If no value exists in the registry or no current process matches the value from the last time
-- your app ran, store the current window handle to the registry for the next time you run
if g_Return == false then
Application.SaveValue(g_RegSection, g_RegKey, Application.GetWndHandle());
end
end
Centauri Soldier
06-23-2007, 09:55 PM
IF you do that, you may consider putting code on your Shutdown Procedures to clear the Registry Entry so the user can open the app again once shutdown.
RizlaUK
06-24-2007, 05:29 AM
to be honest, i wouldn't use the registry at all for some thing like this, it will eventually cause a problem, even if you put code in shutdown to clear the reg entry's if your users pc crashes or they exit the app vis task manager then the shutdown event isent fired, leaving your app unable to run a next time
there is some example code in the manual for this, i would use it rather than the registry
instances_of_file = 0;
file_to_check_for = "autorun.exe"; --have all lowercase
processes = Window.EnumerateProcesses();
for j, file_path in processes do
file = String.SplitPath(file_path);
if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then
instances_of_file = instances_of_file + 1;
end
end
if instances_of_file > 1 then
Window.Hide(Application.GetWndHandle());
Dialog.Message("Error", "Autorun already running: code: already running");
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
else
Window.Show(Application.GetWndHandle());
end
doc13x
06-27-2007, 12:56 PM
Am I wrong or is this going to push the kiosk application itself back up to the top? I need to keep the running application on top in the event that the kiosk application somehow appears over top of the Ministry of Health GPS locator software.
So autorun.exe needs to stay under mohlocator.exe when it is running.
Lorne
06-28-2007, 09:58 AM
To clarify: if an instance of your autoplay app is already running, you want the already-open one to stay open, and the new one to exit, leaving all the current application windows as they are?
In that case something like this might work:
local tbProcesses = System.EnumerateProcesses();
local bAlreadyRunning = false;
for process_id, file_path in tbProcesses do
tbFile = String.SplitPath(file_path);
if(tbFile.Filename .. tbFile.Extension) == _SourceFilename then
if bAlreadyRunning then
--Dialog.Message("Already Running", _SourceFilename .. " is already running.");
Application.Exit();
end
bAlreadyRunning = true;
end
end
If you wanted to allow n instances at a time, you could modify the above to use a counter instead, and exit on nInstances > n.
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.