Announcement

Collapse
No announcement yet.

Terminate AMS program if it does not see another EXE program running

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • rexzooly
    replied
    Originally posted by John Fletcher View Post
    Thanks...

    When using the below code... it does not wait till the yourapp.exe terminates... the application closes immediately...


    Seems to not look... just functions

    nstances_of_file = 0;
    file_to_check_for = "yourapp.exe"; --have all lowercase
    processes = System.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
    IsRunning=true
    Application.ExitScript();
    else
    IsRunning=false
    end
    end

    if not IsRunning then
    Application.Exit(0);
    end

    hmmm that should not happen are they in the same place and is it a solid exe

    Glodal
    Code:
    function appPathOriginal() 
    -- returns the original EXE's path ONLY (with trailing \)
    -- this is useful for compressed single-file apps run from a CD
    -- but, it also works with folder-based apps
    
    local cdPath = ""; 
    local findMarker = "SFXSOURCE:"; 
    local cmdArgs = ""; 
     
    if (Table.Count(_CommandLineArgs) > 0) then 
    	for i = 1, Table.Count(_CommandLineArgs) do 
    		if (String.Find(_CommandLineArgs[i], findMarker) > 0) then 
    			cmdArgs = _CommandLineArgs[i]; 
    			break; 
    		end 
    	end 
    end 
    
    if (cmdArgs ~= "") then 
    if (String.Find(cmdArgs, findMarker) == 1) then 
    local fullPath = String.Replace(cmdArgs, findMarker, "", true); 
    local tblFullPath = String.SplitPath(fullPath); 
    	cd_Path = tblFullPath.Drive .. tblFullPath.Folder; 
    end 
    else 
    	cd_Path = _SourceFolder .. "\\"; 
    end 
    return cd_Path; 
    end
    this will get the reall place of the file but i am not sure you will needed it here
    after pasting it here that other code seems to already look for the path so
    not sure.

    Sorry

    Leave a comment:


  • John Fletcher
    replied
    Just discovered!

    Thanks...

    When using the below code... it does not wait till the yourapp.exe terminates... the application closes immediately...


    Seems to not look... just functions

    nstances_of_file = 0;
    file_to_check_for = "yourapp.exe"; --have all lowercase
    processes = System.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
    IsRunning=true
    Application.ExitScript();
    else
    IsRunning=false
    end
    end

    if not IsRunning then
    Application.Exit(0);
    end

    Leave a comment:


  • longedge
    replied
    It's the "End" that is causing it - should be "end"

    Leave a comment:


  • John Fletcher
    replied
    Currently the On Show code is :

    Page.StartTimer(1000);

    On Timer is :

    EraseClipboard();




    This is the error I get when adding the below code to the startup section

    '=' expected near '<eof>'

    EraseClipboard();

    instances_of_file = 0;
    file_to_check_for = "yourapp.exe"; --have all lowercase
    processes = System.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
    IsRunning=true
    Application.ExitScript();
    else
    IsRunning=false
    end
    end
    if not IsRunning then
    Application.Exit(0);
    End



    Can someone Help with this at all?

    Thanks,

    John

    Leave a comment:


  • RizlaUK
    replied
    yeah, just put it in page timer, but remember to start the timer in page on show "Page.StartTimer(5000)"

    Leave a comment:


  • rexzooly
    replied
    Originally posted by RizlaUK View Post
    call the script from a timer every 5000 ms or so
    how would i do that add the code to on timer page ? or what can i have a little eg of it please thanks RizlaUK.

    Leave a comment:


  • RizlaUK
    replied
    RizlaUK is there away to insted of ending the scipt if it is running but loop so
    the scipt keeps looking until it the program as end and then end its self when
    its ended.
    call the script from a timer every 5000 ms or so

    Leave a comment:


  • rexzooly
    replied
    Originally posted by RizlaUK View Post
    you can call the code from either on startup, page preload/show or call from a timer, all depends on how many times you need to do the check.

    it searches through all running processes, if the process is found then it exits the script, if not it exits the app

    and yes, "yourapp.exe" is the only bit that needs editing
    RizlaUK is there away to insted of ending the scipt if it is running but loop so
    the scipt keeps looking until it the program as end and then end its self when
    its ended.

    Leave a comment:


  • RizlaUK
    replied
    you can call the code from either on startup, page preload/show or call from a timer, all depends on how many times you need to do the check.

    it searches through all running processes, if the process is found then it exits the script, if not it exits the app

    and yes, "yourapp.exe" is the only bit that needs editing

    Leave a comment:


  • John Fletcher
    replied
    If I am looking at this code right - it will run once ?

    or

    Is it repeated and for how many times will it look for the exe file before it terminates?

    Leave a comment:


  • John Fletcher
    replied
    Modifications?

    Hello,

    Is the "yourapp.exe" portion of the code the only portion that needs to be modified?


    ************************************************** ******
    instances_of_file = 0;
    file_to_check_for = "yourapp.exe"; --have all lowercase
    processes = System.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
    IsRunning=true
    Application.ExitScript();
    else
    IsRunning=false
    end
    end

    if not IsRunning then
    Application.Exit(0);
    End

    ************************************************** *****

    Thanks,

    John

    Leave a comment:


  • John Fletcher
    replied
    Tghank You

    Thank you... For your quick responce!!!

    Where do I place this code snippet in the AMS application ?

    Best Regards,

    John

    Leave a comment:


  • RizlaUK
    replied
    a slight edit of the example in the manual

    Code:
    instances_of_file = 0;
    file_to_check_for = "yourapp.exe"; --have all lowercase
    processes = System.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
            IsRunning=true
            Application.ExitScript();
        else
    	IsRunning=false
        end
    end
    
    if not IsRunning then
    	Application.Exit(0);	
    end

    Leave a comment:


  • Terminate AMS program if it does not see another EXE program running

    Hello All,

    Is it possible to have the (No Print Application - System Tray - AMS) once launched seek out and see if the Main application (Demoshield Program) is running - thus if the Main Application (Demoshield Program) has been closed then the (No Print Application - System Tray - AMS) will terminate once it does not see it - Is this possible?

    If so - is there any example code available

    Best Regards,

    John
Working...
X