How do we shut down a triggered app when it's already running?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Protocol
    Indigo Rose Customer
    • Oct 2002
    • 423

    How do we shut down a triggered app when it's already running?

    I need to see if an app is already running before a new instance of it is allowed to open. This seems pretty simple, but there are additional clauses...I may have other AMS apps running (unrelated to this one) so simply looking for "autorun.exe" won't do (since I wouldn't want this app not to launch because a completely different AMS app is running).

    What I want to happen is:

    1) Look for an instance of this application already running
    2) If not, then launch it, if so...then prompt the user that there's already another instance running and offer the user the chance to terminate that instance or to cancel and close the newest attempt to launch the program.
    3) Naturally, it would then need to be able to differentiate between the two (which one to close).

    I've tried several ideas but all of them have drawbacks that are undesireable. Any ideas? Here's the basic code:

    windows = Window.EnumerateTitles();
    window_name = "MyWindowTitle";
    for handle, title in windows do
    result = String.Find(title, window_name, 1, false);
    if (result ~= -1) then
    Window.Close(handle, CLOSEWND_TERMINATE);
    end
    end


    Thanks in advance...

    Protocol
    "White-colla-AMS-gangsta."
  • Worm
    Indigo Rose Customer
    • Jul 2002
    • 3971

    #2
    How 'bout this?

    Name your window "foo" or something else obscure. In the preload, look for the "Actual Window Name"

    if it's found
    Application.Exit()
    else
    Window.SetText(Application.GetWndHandle(), "Actual Window Name")
    end

    Comment

    • TJ_Tigger
      Indigo Rose Customer
      • Sep 2002
      • 3159

      #3
      Couldn't you also get the handle for the new application and add that to the check

      windows = Window.EnumerateTitles();
      window_name = "MyWindowTitle";
      HWND = Application.GetWndHandle();
      for handle, title in windows do
      result = String.Find(title, window_name, 1, false);
      if (result ~= -1) and (HWND ~= handle) then
      Window.Close(handle, CLOSEWND_TERMINATE);
      end
      end
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment

      • Worm
        Indigo Rose Customer
        • Jul 2002
        • 3971

        #4
        Much cleaner solution Tig. I like it.

        Comment

        Working...
        X