PDA

View Full Version : Close browser window?



bhagelin
11-18-2005, 07:06 PM
I have an InstallShield setup program that I launch on a client's system from a web browser. The setup is embedded in an object tag.

The setup program runs fine, but I want the browser window to be automatically closed when the setup program is finished. Is there an InstallScript command that will close a browser window? If that's not possible, is there a way I could kill the IEXPLORE.EXE process?

Thanks...

Christopher Painter
11-18-2005, 10:43 PM
There are many ways. Do a search of this forum for win32_process and process.terminate.

bhagelin
11-21-2005, 01:51 PM
Thanks Christopher. I went ahead and used a Custom Action containing the VBScript that you provided in another thread:


Set objProcs=GetObject("winmgmts:").ExecQuery("select * from Win32_Process where Name='IEXPLORE.exe'")

for each Process in objProcs
Process.Terminate
next


Now I'm wondering if there is a way to select only the most recently opened IE for termination. Perhaps another condition in that Select statement? Do you know if this is possible?

bhagelin
12-05-2005, 11:25 AM
Does anyone know of a way to select only the most recently opened IE for termination, instead of terminating all open IE windows?

Christopher Painter
12-05-2005, 12:11 PM
You can use win32_process.creationdate.

Or you can use PSAPI to enumerate the iexplore processes and figure out which one has the most recent start time.

MSDN Start Page for PSAPI:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/psapi_functions.asp

Very old example of calling PSAPI from InstallScript:

http://www.installsite.org/files/ShutDownRunningApp.zip

Interesting Website dealing with process start time:

http://www.codeproject.com/threads/ProcessTime.asp


That should be enough for you to write your own custom action to kill the most recently started iexplore.exe.

bhagelin
12-05-2005, 02:48 PM
Thanks Chris, the creationdate method was the easiest way. Here is my solution:




Set objProcs=GetObject("winmgmts:").ExecQuery("select * from Win32_Process where Name='notepad.exe'")

Dim sSearchFor, AppOrderExec, AppOrderCurrent

AppOrderExec = 0

for each Process in objProcs
AppOrderCurrent = Process.creationdate
If AppOrderCurrent > AppOrderExec Then
AppOrderExec = AppOrderCurrent
End if
sSearchFor = InputBox(AppOrderExec)
next


for each Process in objProcs
If Process.creationdate = AppOrderExec Then
Process.terminate
End if
next

Christopher Painter
12-05-2005, 03:14 PM
Thanks Chris, the creationdate method was the easiest way. Here is my solution:


Thats about it. If you were using SMS then you could use Extended WQL!

( ooohhhs and ahhhhs from the audience )

Extended WQL supports ORDER BY `field` DESC syntax which means you wouldn't have to walk your collection.


BTW be certain the most recently created browser session is the one you want to kill. I can see a scenario where some program launches a URL request and hijacks an old browser to display the page.