No announcement yet.

Close a running program

  • Filter
  • Time
  • Show
Clear All
new posts

  • Close a running program

    Ulrich's code below posted back in 2011... stops current program from starting if instance of program is already running. I have been playing with it for several days trying to make it close the "running program" and then starting fresh program.

    I am asking for a piece of code that would close the running instance of "myprog" before starting the new instance of "myprog". kindest regards and thank you for all replies.

    -- There can be only one!
    local highlander = 0;
    applications = Window.EnumerateTitles(true);
    for handle, title in pairs(applications) do
    	if (String.Find(title, "Highlander - Powered by AutoPlay Media Studio", 1, false) ~= -1) then
        	highlander = highlander + 1;
    if (highlander > 0) then
    	-- Another instance of the application is already running
    	g_SilentShutdown = true;
    	Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
    	g_SilentShutdown = false;

  • #2
    I should have mentioned: Using AMS Commercial -Win 7 Pro -Licensed. Been reading this forum forever. Started with SUF 1969...

    I do not write code from scratch... I hack code I find.... I am a good person... I do not hack to harm others.... please do not beat me up... I help support software dev by purchasing software as needed. I have been known to pay coders and programmers for help on small projects and just little pieces of scripts... I mostly find code and scripts from google and forums to utilize for my small projects.

    I have read the help file... and have searched the forum... and can not find the code or method to get this specific job done.

    Many thanks to all the AMS Users and Techs that have posted thousands of helpful scripts, examples and replies. And my regrets and sorrows for all the many members that have offered free scripts just to be bombarded with replies that their script is not working or that their script is not practical due to hackers.

    It seems I am stuck in a writing mode... which brings to remembrance "Serializer Action Plugin ". It seemed to be a great piece of code and Forum Member 'Scriptonite' offered it free and received a bad beating for his good deed. Hackers will hack and honest people will buy... it makes me think of my house windows and doors I lock at night, which keeps the honest people out and does not protect me from the dishonest ones.

    Anyway.... I hope I get lucky and get my "closing script".

    Kindest regards,


    • #3
      Not seen anything like that either.

      So you'd need to open a new instance and close the existing one.
      Would something really simple like a file run "my new instance" do it followed by a close command for the current instance?


      • #4
        Trying to get refresh event to occur if new images are added to image folder... slideshow will not show new images without restarting prog. Slideshow located on remote server which causes too many extra steps to log into remote computer to close running slideshow and must restart slideshow to refresh images added to image folder.

        If I knew how to code from scratch... I would have slideshow refresh after last image display... which would resolve this specific issue... and also code a timer event to resolve the 2nd Issue. Heck, if I was really good at coding... I would have a remote file for 'config settings page' which slideshow would read after each complete image cycle... "config settings page" would have timing setup to run different folders based on time of day, settings for image folder location...

        2nd Issue: play different image folders at diff time of day... I can use windows event timer to start the slideshow.exe which plays imagefolder2 vs imagefolder1, however, previous exe continues to play and provokes all the extra time and work to log in remotely to restart the slideshow...

        I would gladly make a financial contribution for such functioning examples... or pm for solicitations or estimates.


        • #5
          Currently reading the help files again... found "Repeat Things at Specific Intervals" and was able to set-up "reload images" at 30 minute increments... utilizing 'On Show' and 'On Timer' events. Resolves the refresh requirement. AMS is a Sweet program.


          • #6
            Originally posted by noveltech View Post
            I am asking for a piece of code that would close the running instance of "myprog" before starting the new instance of "myprog". kindest regards and thank you for all replies.
            I see that you already have a workaround, but this is what you would do to implement what you initially asked:
            local nMyWndHnd = Application.GetWndHandle();
            local tApplications = Window.EnumerateTitles(true);
            for nHandle, sTitle in pairs(tApplications) do
              if ((nHandle ~= nMyWndHnd) and (String.Find(sTitle, "Highlander - Powered by AutoPlay Media Studio", 1, false) ~= -1)) then
                -- close the existing window
                Window.Close(nHandle, CLOSEWND_SENDMESSAGE);
            You also need to remove the definition of QueryAllowProjectClose() in the project that I posted, so the running application will close without asking for confirmation.

            Attached Files


            • #7
              Thank you Ulrich, works just like I hoped for... thank you again.