Indigo Rose Software

Professional Software Development Tools

 
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Dec 2005
    Posts
    7

    Allowing only one instance of an autoplay app to be open

    I'm running an autoplay application from within another autoplay application
    This is the code im using for the button that opens it.

    File.Open("AutoPlay\\Docs\\myapp.exe", "", SW_SHOWNORMAL);

    But if the user clicks the button a few times while the app is loading, it ends up opening many instances of the program.

    I've tried hiding the button once it has been clicked once. but i am looking for a better solution.

    Any ideas on how to only allow one instance of the program to run at any one time?

    Thanks
    Jason

  2. #2
    Join Date
    Oct 2005
    Location
    Brazil - Belo Horizonte
    Posts
    118
    Quote Originally Posted by jason8
    I'm running an autoplay application from within another autoplay application
    This is the code im using for the button that opens it.

    File.Open("AutoPlay\\Docs\\myapp.exe", "", SW_SHOWNORMAL);

    But if the user clicks the button a few times while the app is loading, it ends up opening many instances of the program.

    I've tried hiding the button once it has been clicked once. but i am looking for a better solution.

    Any ideas on how to only allow one instance of the program to run at any one time?

    Thanks
    Jason
    Try this:
    File.Open("AutoPlay\\Docs\\myapp.exe", "AutoPlay\\Docs", SW_SHOWNORMAL);
    I'm not sure but it might work.

  3. #3
    Join Date
    Aug 2003
    Location
    Maine, USA
    Posts
    1,695
    Quote Originally Posted by jason8
    I'm running an autoplay application from within another autoplay application
    This is the code im using for the button that opens it.

    File.Open("AutoPlay\\Docs\\myapp.exe", "", SW_SHOWNORMAL);

    But if the user clicks the button a few times while the app is loading, it ends up opening many instances of the program.

    I've tried hiding the button once it has been clicked once. but i am looking for a better solution.

    Any ideas on how to only allow one instance of the program to run at any one time?

    Thanks
    Jason
    Disable the button when it's clicked.

  4. #4
    Join Date
    Dec 2005
    Location
    Southern California
    Posts
    73
    Im very new to all of this, but I think that using the File.IsInUse command should work. something to this effect:

    function RunOnceOnly()
    CheckRun = File.IsInUse("AutoPlay\\Docs\\myapp.exe");

    if CheckRun == false
    then
    File.Open("AutoPlay\\Docs\\myapp.exe", "", SW_SHOWNORMAL);
    end
    end

    Note: this is really primitive, **** it might not even work properly, but its a start.

    edit: And yea, Ron's idea is probably the best. Unless of course something happened that crashed the app and it did need to be run again.
    Last edited by Gabis; 12-29-2005 at 01:48 PM.

  5. #5
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    I'd suggest something like this...

    Look in the Project On Startup and Global Functions
    Attached Files

  6. #6
    Join Date
    Dec 2005
    Location
    Southern California
    Posts
    73
    you could also use Application.Sleep(5000) or something like that. Would make everything unavailable for 5 seconds (at 5000). Just adjust the time to how long you think it should take your app to launch.

    You could also use Application.Minimize once the button is pressed and use Application.Restore when it is finished running.

    Or do both, if you think someone is going to be pesky enough to try and restore the app just to click the button again =p

  7. #7
    Join Date
    Dec 2005
    Posts
    7
    Gabis - You are fantastic!

    put this into the button code

    CheckRun = File.IsInUse("AutoPlay\\Docs\\myapp.exe");

    if CheckRun == false
    then
    File.Open("AutoPlay\\Docs\\myapp.exe", "", SW_SHOWNORMAL);
    end

    And it works
    Thank you!

  8. #8
    Join Date
    Dec 2003
    Posts
    891
    This will make the app wait (no actions can be run) in minimized mode until the newly started app is closed. Then the window is restored.

    add this to the button On Click

    ---minimize window to get it out of sight
    Window.Minimize(Application.GetWndHandle());
    ---run the desired app with a wait until closed action
    result = File.Run("AutoPlay\\Docs\\myapp.exe", "", "AutoPlay\\Docs", SW_SHOWNORMAL, true);
    ---restores window when app is closed
    Window.Restore(Application.GetWndHandle());

    or to hide the window totally

    Window.Hide(Application.GetWndHandle());
    result = File.Run("AutoPlay\\Docs\\yourapp.exe", "", "AutoPlay\\Docs", SW_SHOWNORMAL, true);
    Window.Show(Application.GetWndHandle());
    Last edited by Roboblue; 12-29-2005 at 02:43 PM.

  9. #9
    Join Date
    Apr 2006
    Location
    Madeira, Portugal
    Posts
    41
    I was wondering how u would get this to work if you ran an application and only wanted it to run once.

    Had a look at the code in Worms example and tried working in some of the code Gabis provided ...

    But the Recipe doesn't exactly work.

    Code:
    CheckRun = File.IsInUse("Portal NetMadeira.exe");
    -- call the global function using the window title
    
    bPrevInstance, nHandle = AppPrevInstance("App Prev Instance");
    
    --if there is a previous instance
    
    if CheckRun == false then
    	--set this window to a small size	
    	Window.SetSize(Application.GetWndHandle(), 0,0)
    	-- move it out of the screen area
    	Window.SetPos(Application.GetWndHandle(), -1000, -1000)
    	-- delete this if you want too
    	Dialog.Message("Already Running", "App is already running")
    	-- bring the previous instance to the front.
    	Window.SetOrder(nHandle, HWND_TOP);
    	--exit this app
    	Application.Exit();
    end
    It won't even let me run the application at all now.

    Guess I should leave the spontaneous cooking to the real Chefs and keep to following their recipes.

    Am guessing I need to only have it exit if there are 2 instances of the same app open .... or use different code.

  10. #10
    Join Date
    Mar 2004
    Location
    Toronto, ON CANADA
    Posts
    696
    I have this in my startup actions to make sure my application can only run once.

    Code:
    nrunning = 0;
    tRunningProcesses = System.EnumerateProcesses();
    for pid, file_path in tRunningProcesses do
    	tpath = String.SplitPath(file_path);
    	sfilename = tpath.Filename..tpath.Extension;
    	if sfilename == "iMediaTouchMenu.exe" then
    		nrunning = nrunning + 1;
    	end
    end
    if nrunning > 1 then
    	result = Dialog.Message("Already Running", "Another instance of iMediaTouch Menu is already running.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    	Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE)
    end

  11. #11
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    Quote Originally Posted by Tek View Post
    I have this in my startup actions to make sure my application can only run once.

    Code:
    nrunning = 0;
    tRunningProcesses = System.EnumerateProcesses();
    for pid, file_path in tRunningProcesses do
    	tpath = String.SplitPath(file_path);
    	sfilename = tpath.Filename..tpath.Extension;
    	if sfilename == "iMediaTouchMenu.exe" then
    		nrunning = nrunning + 1;
    	end
    end
    if nrunning > 1 then
    	result = Dialog.Message("Already Running", "Another instance of iMediaTouch Menu is already running.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    	Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE)
    end

    I like this but if a user changes the name of the program it would not work. I was just thinking about having it check to see if the user changed the name of the app and if so popup a message saying they must change the name back to "whatever your program name is" and if the app matches then run your code to see if it's already running and if any fails exit app.

    I was just thinking what would be the best way to check if the user changed the name.
    If anyone has an idea please reply.
    Last edited by jfxwave; 11-24-2006 at 09:03 AM.

  12. #12
    Join Date
    Mar 2005
    Location
    WA 'wait a while' - Australia
    Posts
    872
    one suggestion is to Settings --> advanced
    and set-decide on some 'file version information' for your distributed autorun.exe

    adapt some of the code bits above to include file.version information
    'matching' and perhaps some myautorun.exe file.getcrc matching aswell

    you could also do a search in forum-s using: multi-instance
    or similar as the search text

    hth a little
    Last edited by Eagle; 11-24-2006 at 09:18 AM.

  13. #13
    Join Date
    Mar 2004
    Location
    Toronto, ON CANADA
    Posts
    696
    Quote Originally Posted by jfxwave View Post
    I like this but if a user changes the name of the program it would not work. I was just thinking about having it check to see if the user changed the name of the app and if so popup a message saying they must change the name back to "whatever your program name is" and if the app matches then run your code to see if it's already running and if any fails exit app.

    I was just thinking what would be the best way to check if the user changed the name.
    If anyone has an idea please reply.
    I don't see why a user would change the name of an application since it would break shortcuts, uninstall procedures, etc.

  14. #14
    Join Date
    Mar 2005
    Location
    WA 'wait a while' - Australia
    Posts
    872
    I try not to assume anything, when it comes to end users

    I include code at runtime that checks the _SourceFolder -install location, crc's etc.
    if runtime verifications not 'correct' ..freindly notification- suggesting to re-install etc

    (intelligence is built in to all installers-updaters -runtimes to cover these scenarios
    as best as possible- what I could think up to dummy-hacker proof ...)

  15. #15
    Join Date
    Mar 2004
    Location
    Toronto, ON CANADA
    Posts
    696
    Well I guess it would depend on the user base, and I know our users would never do that.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. How to Open 3rd Party Media App to Play MPEG?
    By pcc in forum AutoPlay Media Studio 4.0
    Replies: 3
    Last Post: 08-27-2003, 03:49 PM
  2. HOWTO: Create a Project Template
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-28-2002, 01:49 PM
  3. PROBLEM: AutoPlay Application Does Not Start Automatically
    By Support in forum AutoPlay Menu Studio 3.0
    Replies: 0
    Last Post: 10-25-2002, 02:21 PM
  4. PROBLEM: AutoPlay Application Does Not Start Automatically
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-25-2002, 12:39 PM
  5. INFO: Tips for Debugging Action Lists in AutoPlay Media Studio 4.0
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-03-2002, 08:38 AM

Posting Permissions

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