Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get window title from PID

2,447 views
Skip to first unread message

roger...@gmail.com

unread,
Apr 14, 2009, 3:28:28 PM4/14/09
to
On some of my devices, I have a application that my users have that
attaches them to one particular system, while they are in that system
they need to run various IE windows that will interface, communicate,
etc.

We have created a VBScript that monitors when they are attached to the
system and when that EXE is closed will close all of the open IE
windows.

Because of the way these devices are used, we don't want them opening
IE windows except when they are attached to that particular system and
our script work beautifully in that respect.

BUT - There is also another IE window that is normally open on the
device that is locked to a specific site/url that we don't care if
they are attached to the other system when they are using.

How do I NOT kill that particular IE window? I think that testing for
the window title - which does not change or the site url/ipaddress
would be best but I am at a loss on how to gather this information.

I am currently using the following code:

Set colProcessList = objWMIService.ExecQuery ("Select * from
Win32_Process Where Name = 'myprogram.exe'")
if colProcessList.count > 0 then
Set colProcessList2 = objWMIService.ExecQuery ("Select * from
Win32_Process Where Name = 'iexplore.exe'")
if colProcessList2.count > 0 then
objProcess2.Terminate() *******
end if
end if

what I would like to do is change the line marked with ******* to
something like this:

if title is not <blah> or url is not <xyz.com> then
objProcess2.Terminate()
end if

I can obviously get the process id, is there any way to use that to
gather the necessary information?

Any thoughts?

Alex K. Angelopoulos at

unread,
Apr 14, 2009, 6:06:36 PM4/14/09
to
I can't see a specific way to get the window title from the PID, but based
on your description - and my assumption that you're doing this from a
locally running WSH script or HTA - there's an easier way to handle the
problem. Go in through simple IE window enumeration using a
Shell.Application COM object instance. Here's a demo of a simple script that
first culls out the desktop windows that are for filesystem browsing, then
checks the LocationUrl property for each of the other windows. If it is
"about:blank", they are closed.

One other fringe benefit of this approach is that if you ever move to tabbed
browsers, this code isn't going to break due to accidentally close the
hidden "parent" IE container.

To adapt it to your situation, you probably want to use another loop like
the one that checks for "file:", only using a short unique initial substring
that identifies the site you don't mind leaving open.


set sa = CreateObject("Shell.Application")
Set windows = sa.Windows()
for each window in sa.windows
if left(window.LocationUrl, 5) <> "file:" then
' logic for selecting windows goes here
if window.locationUrl = "about:blank" then window.Quit()
end if
next

<roger...@gmail.com> wrote in message
news:7133fdf5-805b-4f1b...@j12g2000vbl.googlegroups.com...

0 new messages