Indigo Rose Software
  #1  
Old 10-07-2004
Brett's Avatar
Brett Brett is offline
Indigo Rose Staff Member
 
Join Date: Jan 2000
Posts: 2,001
Lightbulb Function: FindAndCloseProcessByName

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
To call the function from your project, try copying and pasting the following script onto an action tab, such as the On Startup event. You can get there by choosing Project > Actions.
Code:
-- Close Internet Explorer if running
FindAndCloseProcessByName("iexplore.exe");
Function Name: FindAndCloseProcessByName
Type: Setup Factory 7.0 Function
Created By: Brett Kapilik

Comments? Please post them here.
Reply With Quote
  #2  
Old 03-12-2005
Frackounet Frackounet is offline
Forum Member
 
Join Date: Mar 2005
Posts: 1
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
To call the function from your project, try copying and pasting the following script onto an action tab, such as the On Startup event. You can get there by choosing Project > Actions.

Code:
-- Close MSN Messenger if running
FindAndCloseProcessByName("msnmsgr.exe");
Reply With Quote
  #3  
Old 03-12-2005
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,059
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)."
__________________
Intrigued
www.amsuser.com
Reply With Quote
  #4  
Old 12-11-2005
ddstrg ddstrg is offline
Forum Member
 
Join Date: Dec 2005
Posts: 1
Very good,
Thanks you!
Reply With Quote
  #5  
Old 12-22-2005
TuanKTCDCN TuanKTCDCN is offline
Forum Member
 
Join Date: Dec 2005
Posts: 8
FindAndCloseProcessByClass?

Help me to create a function FindAndCloseProcessByClass(strClass)
Thanks a lot!
Reply With Quote
  #6  
Old 06-06-2006
Staggan Staggan is offline
Forum Member
 
Join Date: Apr 2006
Posts: 69
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
Reply With Quote
  #7  
Old 06-06-2006
Staggan Staggan is offline
Forum Member
 
Join Date: Apr 2006
Posts: 69
Its ok, I resolved this issue.

Thanks
Reply With Quote
  #8  
Old 06-07-2006
Adam's Avatar
Adam Adam is offline
Indigo Rose Staff Member
 
Join Date: May 2000
Location: Indigo Rose Software
Posts: 2,154
Good to hear.

Adam Kapilik
Reply With Quote
  #9  
Old 02-06-2007
kymaita kymaita is offline
Forum Member
 
Join Date: Jan 2007
Posts: 12
Cool closing which seems Multithread application

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
Reply With Quote
  #10  
Old 06-21-2007
pww's Avatar
pww pww is offline
Forum Member
 
Join Date: Jun 2005
Posts: 343
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;
Reply With Quote
  #11  
Old 01-08-2009
kk250040's Avatar
kk250040 kk250040 is offline
Forum Member
 
Join Date: Feb 2008
Posts: 81
Grin Detect a batch file running

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
Reply With Quote
  #12  
Old 4 Weeks Ago
DanCooperstock DanCooperstock is offline
Indigo Rose Customer
 
Join Date: Mar 2003
Location: Toronto ON
Posts: 26
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
This would likely be called in one of your Next button actions, and the installer would be exited if it returned false.
__________________
Dan Cooperstock info@Software4Nonprofits.com
416-423-7722
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software