|
#1
|
||||
|
||||
|
Function: FindAndCloseProcessByName
Last Revision: October 7, 2004 (001) Information This function can be used to find a process by it's filename and then close it by sending it a close message. To use this function in your Setup Factory 7.0 projects, simply copy and paste it into your Global Functions. You can get there by selecting Resources > Global Functions from the main menu. Code:
function FindAndCloseProcessByName(strName) local tblProcesses = Window.EnumerateProcesses(); local bProcessFound = false; local nProcessHandle = nil; if(tblProcesses)then local strProcessName; local nHandle; for nHandle, strProcessName in tblProcesses do if(String.Find(strProcessName,strName,1,false) ~= -1)then nProcessHandle = nHandle; bProcessFound = true; end end end if(bProcessFound and nProcessHandle)then Window.Close(nProcessHandle,CLOSEWND_SENDMESSAGE); end end Code:
-- Close Internet Explorer if running
FindAndCloseProcessByName("iexplore.exe");
Type: Setup Factory 7.0 Function Created By: Brett Kapilik Comments? Please post them here. |
|
#2
|
|||
|
|||
|
Here the code for programs like MSN Messenser, the CLOSEWND_SENDMESSAGE don't close completly the program.
Change it in CLOSEWND_TERMINATE Information This function can be used to find a process by it's filename and then close it by sending it a close message. To use this function in your Setup Factory 7.0 projects, simply copy and paste it into your Global Functions. You can get there by selecting Resources > Global Functions from the main menu. Code:
function FindAndCloseProcessByName(strName) local tblProcesses = Window.EnumerateProcesses(); local bProcessFound = false; local nProcessHandle = nil; if(tblProcesses)then local strProcessName; local nHandle; for nHandle, strProcessName in tblProcesses do if(String.Find(strProcessName,strName,1,false) ~= -1)then nProcessHandle = nHandle; bProcessFound = true; end end end if(bProcessFound and nProcessHandle)then Window.Close(nProcessHandle,CLOSEWND_TERMINATE); end end Code:
-- Close MSN Messenger if running
FindAndCloseProcessByName("msnmsgr.exe");
|
|
#3
|
||||
|
||||
|
Here is a footnote to remember though and it may or may not affect said application being terminated (closed):
"Immediately terminate the program's process. The state of global data maintained by the program's dynamic-link libraries (DLLs) may be compromised if this option is used. (When this option is selected, the AutoPlay application calls the Windows API function "TerminateProcess" to immediately terminate the specified program.)" and, this was interesting to find in another area: "Tip: Pro Edition users can use Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE) in place of Application.Exit(). This will close the window before the window draws itself (i.e. the user will see nothing)." |
|
#4
|
|||
|
|||
|
Very good,
Thanks you! |
|
#5
|
|||
|
|||
|
FindAndCloseProcessByClass?
Help me to create a function FindAndCloseProcessByClass(strClass)
Thanks a lot! |
|
#6
|
|||
|
|||
|
This function is extremely useful...
How can I get it to close ALL instances of explorer though if the user has multiple browsers open ? It works fine for single windows... but any more than 1 and it leaves the rest open... Thanks |
|
#7
|
|||
|
|||
|
Its ok, I resolved this issue.
Thanks |
|
#8
|
||||
|
||||
|
Good to hear.
Adam Kapilik |
|
#9
|
|||
|
|||
|
Hi
I'm testing TrueUpdate software and I'm just in this Step. I want to close my application if it is running at the moment an update is available and user press a next button after accepting the license agreement. I tried this code ( FindAndCloseProcessByName) with a sample windows form application made in .Net 2.0 and it works well but my application is like Messenger application run minimized in system try . One feature of my application is that it has timers running in the background and those timers stop the application for closing; maybe because those timers run in separate threads. I need to use a more powerful instruction to dispose the application and all threads associated to it. What can I do? Kenny |
|
#10
|
||||
|
||||
|
cool, but closes only one instance of the app.
In case it's possible more than one instance of the app to be opened (as is the case for most apps), should be something like this Code:
function FindAndCloseProcessByName(strName) local tblProcesses = Window.EnumerateProcesses(); if(tblProcesses)then local strProcessName; local nHandle; for nHandle, strProcessName in tblProcesses do if(String.Find(strProcessName,strName,1,false) ~= -1)then Window.Close(nHandle,CLOSEWND_SENDMESSAGE); end; end; end; end; |
|
#11
|
||||
|
||||
|
Hello friends,
What if i need to detect a batch file running. I can check for the "cmd.exe", but there are chances that the user opens his own cmd.exe for some other purposes. Is there any other way of detecting a batch file running. My batch file consists of scripts to take backup of the host machine. But when i tried to detect the "xcopy.exe" for the copy command in the bacth file, its not being detected though the list of processes in task manager show the xcopy.exe in the list. So how do i detect this kind of a bacth file running... Please suggest me how i can do it... Thanks, Kusuma |
|
#12
|
|||
|
|||
|
Close application with confirmation
Here's a version of the code above, that is for checking whether the application being installed is currently running (rather than the installer), since that is likely to cause a lot of files to be unable to be installed. It confirms whether it's OK to stop the app.
Code:
-- Look for an existing instance of strName, ask whether it's
-- OK to close it, return true if there was no instance or we
-- closed it, false otherwise
function FindAndCloseDonation(strName)
local tblProcesses;
local bProcessFound = true;
while bProcessFound do
tblProcesses = Window.EnumerateProcesses();
bProcessFound = false;
if (tblProcesses) then
local strProcessName;
local nHandle;
for nHandle, strProcessName in tblProcesses do
if (String.Find(strProcessName,strName) ~= -1) then
if Dialog.Message("Already Running", "Your application is currently running, and the installation cannot complete while it is running.\n\nIs it OK for the application to be closed, before continuing this installation?",
MB_YESNO, MB_INCONQUESTION) == IDYES then
bProcessFound = true;
Window.Close(nHandle, CLOSEWND_TERMINATE);
Application.Sleep(1000);
else
return false;
end
end
end
end
end
return true -- not found, or successfull closed
end
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Another tough one... Interaction between Web and AMS | Agent Jones | AutoPlay Media Studio 5.0 | 13 | 08-18-2005 03:10 PM |
| Function: String.RandomFromPattern | Brett | Setup Factory 8.0 Examples | 0 | 10-28-2004 09:09 AM |
| Bizarre Callback Function Behaviour - Can anyone help? | SRJ | AutoPlay Media Studio 5.0 | 3 | 06-30-2004 10:16 PM |
| Function: Test Whether An Input Object Is Empty | Lorne | AutoPlay Media Studio 5.0 Examples | 0 | 06-08-2004 03:18 PM |
| Function: Resize & Center an Image | kpsmith | AutoPlay Media Studio 5.0 Examples | 0 | 05-17-2004 02:36 PM |
All times are GMT -6. The time now is 12:43 AM.








Linear Mode

