Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014

    Killing an instance

    I need to kill a PowerPoint.exe/instance any ideas?
    ie. function TerminatePowePoints()

  2. #2
    Join Date
    May 2006
    Posts
    5,380
    is there any reason why the below code wont work with powerpoint ?

    Code:
    instances_of_file = 0;
    file_to_check_for = "powerpoint.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
            System.TerminateProcess(j);
        end
    end
    or is it that you just want to kill 1 of many running instances
    Open your eyes to Narcissism, Don't let her destroy your life!!

  3. #3
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Quote Originally Posted by RizlaUK View Post
    is there any reason why the below code wont work with powerpoint ?

    Code:
    instances_of_file = 0;
    file_to_check_for = "powerpoint.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
            System.TerminateProcess(j);
        end
    end
    or is it that you just want to kill 1 of many running instances
    I've seen this code RizlaUK good find, I have run into another problem sence I posted dealing w/ the timer event which is where this code belongs. I'll update after I speak w/ Tigg.
    Oh BTY I wnat to kill any instances that pop-up as the end user is taking a test. Thanks for your reply.

  4. #4
    Join Date
    May 2006
    Posts
    5,380
    just place that code in the timer, set the timer for 1000 and it will check for all instances of powerpoint.exe every second, any cheaters will have to be real fast readers!
    Open your eyes to Narcissism, Don't let her destroy your life!!

  5. #5
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Ok I have this on timer:

    instances_of_file = 0;
    file_to_check_for = "pptview.exe";
    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
    System.TerminateProcess(j);
    end
    end

    And the timer set for:

    Page.StartTimer(1000);

    NOT working

    Unless the system sees it as something else.

    OK I found what it's really called: file_to_check_for = "POWERPNT.EXE";
    the red below I think is causing an issue

    if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then

    Ideas?
    Last edited by Bruce; 11-02-2008 at 05:17 PM.

  6. #6
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    errrrr "Upper"

  7. #7
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Funny, this will not stop another instance of the program if it's running from the same CD, file_to_check_for = "POWERPNT.EXE"; or file_to_check_for = "autorun.exe";. Not good

  8. #8
    Join Date
    Oct 2006
    Posts
    345
    as pointed out you need to be 100% correct in case sensitivity, best to use the code as supplied and make sure your file name is in lowercase also, i'd make it check for both examples of the file name... with and without the file type

    as for your last post, you have a stray ; in the middle of your script

  9. #9
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    Quote Originally Posted by qwerty View Post
    also, i'd make it check for both examples of the file name... with and without the file type

    as for your last post, you have a stray ; in the middle of your script
    "with and without the file type" explane
    "you have a stray ;"
    Where?

  10. #10
    Join Date
    Oct 2006
    Posts
    345
    ok, my bad.... i see you were using the OR as it normally is in speach/typing, i thought that line you typed was part of your code, i get it now that you meant

    file_to_check_for = "POWERPNT.EXE";

    or

    file_to_check_for = "autorun.exe";




    for the other thing, in the script you have it sorting out the filename and extension, joining the 2 texts together prior to comparing with your file to check for, i tend to do it this way just to cover the bases....
    Code:
    if (String.Lower(file.Filename..file.Extension)) == "POWERPNT.EXE" or (String.Lower(file.Filename)) == "POWERPNT" then -- must be in lowercase here
    in theory, this will allow you to trigger the same action code after the "then" for 2 different filenames, one compared using the filename+extension and one just by filename

  11. #11
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    This worked for me

    Code:
    --Define a table of application names you don't want running during this time
    --This table includes powerpoint and the powerpoint viewer.
    tbfiles_to_check_for = {"powerpnt.exe","pptview.exe","powerpoint.exe"}; --have all lowercase
    
    --Enumerate the system processes 
    processes = System.EnumerateProcesses();
    
    --loop through the table looking at each process
    for j, file_path in processes do
    	--Split the filepath into a table
        file = String.SplitPath(file_path);
        --Combine the filename and extension so we can compare
        -- with the table of processes we defined above
        strFnExt = String.Lower(file.Filename..file.Extension);
        --loop through the table containing the filenames for us to check
        for i,filenamecheck in tbfiles_to_check_for do
        	--compare each entry against the process name plus extension
    	    if strFnExt == filenamecheck then
    	    	--if there is a match then terminate that process
    	        System.TerminateProcess(j);
    	    end
    	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

  12. #12
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    WOW, I'll try it out! Thx Tigg.

  13. #13
    Join Date
    Apr 2005
    Location
    Allentown, PA.
    Posts
    52
    I am also trying to kill an instance, I am able to (System.TerminateProcess) but for some reason the taskbar tray icon remains until I move the mouse over it then it disappears as it should.
    Is there anyway to make the icon disappear on its own?

    Thanks.

    ----------------------
    Douglas Greaser
    DRG EFFECTS
    Last edited by drgfx; 01-19-2009 at 05:44 PM.

  14. #14
    Join Date
    Mar 2006
    Posts
    61
    Quote Originally Posted by drgfx View Post
    I am also trying to kill an instance, I am able to (System.TerminateProcess) but for some reason the taskbar tray icon remains until I move the mouse over it then it disappears as it should.
    Is there anyway to make the icon disappear on its own?

    Thanks.

    ----------------------
    Douglas Greaser
    DRG EFFECTS
    Because you are 'terminating' a process, that process is not "allowed" so to speak, to enter any possible shutdown sequences it may have. In this case the terminated application is not allowed to release the trayicon from the system tray. For this reason it is generally better to ASK the application to shutdown rather then terminate it. But if the application is needing to be terminated then of course terminate it.

    This sends a request to the application to shut down, it is a polite way to close a running program because you simply say "Hey mr. program, will you close please?"
    Code:
    Window.Close(application_handle, CLOSEWND_SENDMESSAGE)
    This is a rude way to close an application. It's like saying "die die DIIIEEE!!" and not giving the application a chance to respond. It is the same when working with System.TerminateProcess().
    Code:
    Window.Close(application_handle, CLOSEWND_TERMINATE);
    The biggest difference between the 2 ways of terminating an application [System.TerminateProcess() & Window.Close(TERMINATE)] is that System.TerminateProcess() uses the PID (Process ID) and Window.Close() uses window handles. In essence the two do the same thing, they both impolitely close a program.

    There are things to think about though when you want to close an application.
    For instance:
    Is my closing this program a priority before it can carry out any extra orders?
    Does this application need to be politely shut down so that any changes to it can be properly saved, and it can carry out any freeing of resources it might need to do.

    Or things like that. In your case to allow the application to properly shutdown and release the system tray icon you should politely ask it to close. However, you need to find the window handle of the application which is not the same as the ProcessID required for System.TerminateProcess()

    The example for the System.TerminateProcess() in AMS7's help will work just fine for enumerating the windows and closing the one you want, you just have to change to using the equivalent Window functions in place of the System functions.

    An example of what I mean:
    Code:
    local String, Window = String, Window; -- speed up these functions by making them local to this chunk
    local file_to_check_for = "autorun.exe"; --have all lowercase
    local processes = Window.EnumerateProcesses();
    
    for wnd_handle, file_path in processes do
    	local file = String.SplitPath(file_path);
    	if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then
    		Window.Close(wnd_handle, CLOSEWND_TERMINATE);
    		Window.Close(wnd_handle, CLOSEWND_SENDMESSAGE);
    	end
    end

    So basically, unless the program you want to shut down is a threat or just absolutely needs to be terminated, you should ask it to close. And if you find that asking it to close doesn't close it then of course you need to die die DIEEE the sucker!
    Last edited by Bags; 01-20-2009 at 08:03 AM.

  15. #15
    Join Date
    Apr 2005
    Location
    Allentown, PA.
    Posts
    52
    Thank you that is an excellent description!

    The app I'm "killing" is minimized to the system tray, and is why I have to terminate it.
    Just tried your example to make sure it didn't fix the problem.
    I tried many ways/ideas when I originally set it up, including maximizing it to close.
    Finally I had to use the following code :


    Code:
    instances_of_file = 0;
    file_to_check_for = "alert.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
            System.TerminateProcess(j);
        end
    end
    Only problem is that darn icon hangs in the taskbar tray after the termination. : (
    Was thinking of using : SendTo(nSendHWnd, "HWND", and sending a close command to the app that way.
    Just haven't got around to trying it yet..

    Thanks for the reply.

    ----------------------
    Douglas Greaser
    DRG EFFECTS
    Last edited by drgfx; 01-21-2009 at 01:05 AM.

Similar Threads

  1. Checking if there's already another instance of AMS running?
    By Protocol in forum AutoPlay Media Studio 7.5
    Replies: 2
    Last Post: 10-06-2008, 07:27 AM
  2. New Problem!!! Killing Me Softly :)
    By siray in forum AutoPlay Media Studio 7.5
    Replies: 4
    Last Post: 06-28-2008, 01:20 PM
  3. Single Instance of AutoPlay executable
    By mitjpl in forum AutoPlay Media Studio 6.0
    Replies: 8
    Last Post: 04-01-2007, 05:04 PM
  4. Single Instance
    By mitjpl in forum AutoPlay Media Studio 6.0
    Replies: 1
    Last Post: 03-29-2007, 09:02 PM
  5. search doesn't work in a specific instance
    By intel352 in forum Setup Factory 6.0
    Replies: 8
    Last Post: 03-27-2003, 12:56 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