I am working on a simple VBScript that instantiates IE 6. My script then
proceeds to â??driveâ?? IE by reading urls from a text file. I use this script
for testing various websites. The problem is that from time to time I come
across sites with popups of various forms. Can I detect new IE windows being
fired up by these sites and either kill them off or do a KeySend (or is it
SendKey) to simple click CANCEL?

I have seen another script that fetches off the window handles as in
win.HWND. Would this be a way? And if so, once I fetch of the handle, how do
I manipulate (i.e. kill ) the new window by using its handle?

Thanks

P.S. can something similar be done for Firefox? Is there a vbscript that
"drives" firefox?

Re: Automation of IE and detection of popups using VBScript by mr_unreliable

mr_unreliable
Fri Jun 24 16:23:32 CDT 2005

hi llamaflaca,

If you know the captions of the popup windows, you could use AppActivate
as a function, to detect their presence.

A better bet would be just to use one of the free (or commercial) popup
blockers.

Otherwise, you might be better off writing your "script" in vb (or some
other language allowing api calls), where you could use api's to detect
the appearance of popup windows. For example, I wrote a script to
dismiss cookie alerts from IE, but I was using a third-party control
to call api's from script. My script will also dismiss zone alarm
alerts, using the same technique. (I could just turn off the alerts,
but I prefer to see them briefly, so as to know what's really going
on).

As for firefox, imho it already does a great job of blocking popups.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)





llamaflaca wrote:
> I am working on a simple VBScript that instantiates IE 6. My script then
> proceeds to â??driveâ?? IE by reading urls from a text file. I use this script
> for testing various websites. The problem is that from time to time I come
> across sites with popups of various forms. Can I detect new IE windows being
> fired up by these sites and either kill them off or do a KeySend (or is it
> SendKey) to simple click CANCEL?
>
> I have seen another script that fetches off the window handles as in
> win.HWND. Would this be a way? And if so, once I fetch of the handle, how do
> I manipulate (i.e. kill ) the new window by using its handle?
>
> Thanks
>
> P.S. can something similar be done for Firefox? Is there a vbscript that
> "drives" firefox?
>

Re: Automation of IE and detection of popups using VBScript by shadowHead

shadowHead
Fri Jun 24 16:45:10 CDT 2005

Thanks Mr_unreliable. I will pass on 3rd party blockers for now. I
have gotten some success so far with the following script even though I
do not know the captions of the popups. ...

Option Explicit
Dim shl, wins, i, x, win, result, mainIE, IE, popup, colWindow
Set shl = CreateObject("Shell.Application")
set wins = shl.windows

for i = 0 to wins.count - 1
Set IE = wins.item(0)
mainIE = IE.HWND
Set win = wins.item(i)
WScript.Echo win.HWND
MsgBox mainIE & " main window", vbInformation, "IE Handles"
next
'MsgBox mainIE, vbInformation, "IE Handles"
while (1)
Wscript.sleep 2000
if wins.count > 1 then
for each colWindow in wins
if colWindow.HWND <> mainIE then
colWindow.Quit()
end if
next
end if
wend

It seems to work for most of them except modaless windows and a couple
of other varieties. As long as I only have 1 Window open then this
kills all new IE windows. This serves my needs for now. But still how
would I handle modeless windows? Hmmm???

My questions is: Can't I get into the API with VBScript. What about
WebBrowser2 and others? I thought there was a way. Any ideas?


Re: Automation of IE and detection of popups using VBScript by llamaflaca

llamaflaca
Fri Jun 24 16:52:03 CDT 2005

Thanks Mr_unreliable. I will pass on 3rd party blockers for now. I
have gotten some success so far with the following script even though I
do not know the captions of the popups. ...


Option Explicit
Dim shl, wins, i, x, win, result, mainIE, IE, popup, colWindow
Set shl = CreateObject("Shell.Applicatio­n")
set wins = shl.windows


for i = 0 to wins.count - 1
Set IE = wins.item(0)
mainIE = IE.HWND
Set win = wins.item(i)
WScript.Echo win.HWND
MsgBox mainIE & " main window", vbInformation, "IE Handles"
next
'MsgBox mainIE, vbInformation, "IE Handles"
while (1)
Wscript.sleep 2000
if wins.count > 1 then
for each colWindow in wins
if colWindow.HWND <> mainIE then
colWindow.Quit()
end if
next
end if
wend


It seems to work for most of them except modaless windows and a couple
of other varieties. As long as I only have 1 Window open then this
kills all new IE windows. This serves my needs for now. But still how
would I handle modeless windows? Hmmm???


My questions is: Can't I get into the API with VBScript. What about
WebBrowser2 and others? I thought there was a way. Any ideas?


"mr_unreliable" wrote:

> hi llamaflaca,
>
> If you know the captions of the popup windows, you could use AppActivate
> as a function, to detect their presence.
>
> A better bet would be just to use one of the free (or commercial) popup
> blockers.
>
> Otherwise, you might be better off writing your "script" in vb (or some
> other language allowing api calls), where you could use api's to detect
> the appearance of popup windows. For example, I wrote a script to
> dismiss cookie alerts from IE, but I was using a third-party control
> to call api's from script. My script will also dismiss zone alarm
> alerts, using the same technique. (I could just turn off the alerts,
> but I prefer to see them briefly, so as to know what's really going
> on).
>
> As for firefox, imho it already does a great job of blocking popups.
>
> cheers, jw
> ____________________________________________________________
>
> You got questions? WE GOT ANSWERS!!! ..(but,
> no guarantee the answers will be applicable to the questions)
>
>
>
>
>
> llamaflaca wrote:
> > I am working on a simple VBScript that instantiates IE 6. My script then
> > proceeds to â??driveâ?? IE by reading urls from a text file. I use this script
> > for testing various websites. The problem is that from time to time I come
> > across sites with popups of various forms. Can I detect new IE windows being
> > fired up by these sites and either kill them off or do a KeySend (or is it
> > SendKey) to simple click CANCEL?
> >
> > I have seen another script that fetches off the window handles as in
> > win.HWND. Would this be a way? And if so, once I fetch of the handle, how do
> > I manipulate (i.e. kill ) the new window by using its handle?
> >
> > Thanks
> >
> > P.S. can something similar be done for Firefox? Is there a vbscript that
> > "drives" firefox?
> >
>

Clarificaton by mr_unreliable

mr_unreliable
Sat Jun 25 11:48:34 CDT 2005

It was a bit presumptuous to just say that calling api's was better
than "pure" script (in blocking popups).

Generally speaking, with "pure" script you are forced to deal with
EXISTING windows -- they must appear before you can deal with them,
and then not very effectively or satisfactorily.

In contrast, with api's you can "set a system hook", to request that
the system send you a notification whenever it is opening a window.
Further, you can get your notification BEFORE the window is shown
-- while it is still being created -- allowing you to make
modifications during the creation process.

In an application where you are seeking to discard popup windows,
getting a notification before the window appears allows you to hide
it or close it, or destroy it. All of which will effectively
get rid of it.

The system hooks I am talking about are the "CBT Hook" (wh_cbt),
and the "Shell Hook" (wh_shell). While they serve different
porposes, both of these hooks will provide notifications about
windows opening events.

There are plenty of (vb) code examples at the various vb source
code websites, in case anybody is interested in getting into
hooking...

As far as the notion of "getting into api's from script", it IS
possible, using a third-party control. But then most scripters,
especially sysadmins, TOTALLY REFUSE to use third-party controls.
Further, one of the "popular" controls for calling api's (Dynawrap)
does not allow for many of the more esoteric aspects of calling
api's (such as typedefs, [out] parameters, calling by ordinal
instead of entry point name, and so on)...

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


Re: Clarificaton by shadowHead

shadowHead
Sat Jun 25 18:37:27 CDT 2005

Outstanding information. Thanks !. I kinda knew about hooks although I
have never programmed one. Scripting was my down and dirty (and
certainly half-baked) way to resolve 90% of the issues I am dealing
with right now.

Thanks again for the great info.

Shadow


Re: Automation of IE and detection of popups using VBScript by Fosco

Fosco
Sat Jun 25 11:44:02 CDT 2005

"shadowHead"

PopUP Killer.vbs
' (don't remember the author >> www.google.com "PopUP Killer+vbs")

Dim gstrDataFile 'As String -- Name of text file containing bad window titles
Dim strEngine 'As String -- Used to tell the user what program is running the wscript.
gstrDataFile = FileNameLikeMine("txt")
If Not CreateObject("Scripting.FileSystemObject").FileExists(gstrDataFile) Then
String2File "----- Title Data File -----" & vbCrLf & "www.quellochevuoi" & vbCrLf & "about:blank" & vbCrLf,
gstrDataFile
strEngine = Wscript.FullName
strEngine = Mid(strEngine, InstRrev(strEngine, "\") + 1)
strEngine = Left(strEngine, Instr(strEngine, ".") - 1)
strEngine = Ucase(Left(strEngine, 1)) & Lcase(Mid(strEngine, 2))
MsgBox " This script will run until system shutdown killing windows whose titles are found in the ""Title Data
File"" at """ & gstrDataFile & """." & vbCrLf & vbCrLf & " If you need to stop this process, kill the """ &
strEngine & """ program with the Windows Task Manager (Ctrl-Alt-Del). Alternatively, you can stop the program by
deleting, renaming, or emptying the title data file." & vbCrLf & vbCrLf & " This dialog will only appear when there
is no title data file."
End If
While True
KillWindows
Wscript.Sleep 500
Wend


Sub KillWindows
Dim wsh 'As WScript.Shell
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Dim strData 'As String -- Entire contents of gstrDataFile
Dim strTitle 'As String -- Just one bad window title
Const ForReading = 1
Set fs = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
On Error Resume Next
Err.Clear
Set ts = fs.OpenTextFile(gstrDataFile, ForReading, True)
If Err.Number = 0 Then
strData = ts.ReadAll
If Err.Number = 0 Then
'Read all title lines in data string
Do Until (Instr(strData, vbCrLf) = 0)
strTitle = Left(strData, Instr(strData, vbCrLf) - 1)
strData = Mid(strData, Instr(strData, vbCrLf) + 2)
If strTitle <> "" Then
If wsh.AppActivate(strTitle) Then
wsh.SendKeys "%{F4}"
WriteLog Now & " " & strTitle
End If
End If
Loop
'Grab last bit in case there was no ending CrLf
strTitle = strData
If strTitle <> "" Then
If wsh.AppActivate(strTitle) Then
wsh.SendKeys "%{F4}"
WriteLog Now & " " & strTitle
End If
End If
Else
ts.Close
Wscript.Quit 1
End If
Else
Wscript.Quit 1
End If
ts.Close
End Sub

Sub WriteLog(strText)
'Write to screen if script is run with CSCRIPT. Otherwise, write to a log file.
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Const ForAppending = 8
If Lcase(Right(Wscript.FullName, 11)) = "cscript.exe" Then
Wscript.Echo strText
Else
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log",
ForAppending, True)
ts.WriteLine strText
ts.Close
End If
End Sub

Function FileNameLikeMine(strFileExtension) 'As String
'Returns a file name the same as the script name except
'for the file extension.
Dim fs 'As Object
Dim strExtension 'As String
Set fs = CreateObject("Scripting.FileSystemObject")
strExtension = strFileExtension
If Len(strExtension) < 1 Then strExtension = "txt"
If strExtension = "." Then strExtension = "txt"
If Left(strExtension,1) = "." Then strExtension = Mid(strExtension, 2)
FileNameLikeMine = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & strExtension
End Function

Sub String2File(strData, strFileName)
'Writes a string to a file
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Const ForWriting = 2
Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(strFileName, ForWriting, True)
ts.Write(strData)
ts.Close
End Sub

--
Fosco