Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2005
    Posts
    35

    Kiosk - prevent multiple launch of software?

    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.

  2. #2
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534
    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

  3. #3
    Join Date
    Oct 2005
    Location
    MI
    Posts
    524
    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.
    Code:
    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
    Yeah right. Who's the only one here who knows the illegal ninja moves from the government?

    ()))))))))o)))))))==============================================

  4. #4
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534
    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.

  5. #5
    Join Date
    May 2006
    Posts
    5,380
    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
    Code:
    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
    Open your eyes to Narcissism, Don't let her destroy your life!!

  6. #6
    Join Date
    May 2005
    Posts
    35

    But...?

    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.

  7. #7
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    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:

    Code:
    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.
    --[[ Indigo Rose Software Developer ]]

Similar Threads

  1. Run Multiple .Wav Files with External Software
    By shamballa in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 02-01-2007, 03:03 PM
  2. Multiple Software Applications with Single Update Check
    By smanners in forum TrueUpdate 2.0
    Replies: 3
    Last Post: 10-02-2006, 09:09 AM
  3. How to launch multiple setups?
    By JoeDul in forum Setup Factory 7.0
    Replies: 3
    Last Post: 05-16-2005, 07:57 AM
  4. Frequently Asked Questions
    By Ted Sullivan in forum Visual Patch 2.0
    Replies: 0
    Last Post: 04-08-2005, 02:49 PM
  5. HOW to give a shortcut a multiple launch ??
    By saphirot in forum Setup Factory 6.0
    Replies: 2
    Last Post: 01-10-2004, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts