Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - IE automation question

Reply
 
Old 02-08-2009   #1 (permalink)
MIS42N


 
 

IE automation question

I am driving IE from an external vbscript (cscript xxx.vbs). I can
make IE do everything that I want, but the VBS<->IE communication
isn't very elegant and it's probably
non standard. Is there (i) a way to to suspend a script until IE
wakes it, and (ii) a way to get vbs to trigger an IE function
directly?

What the script does is get some input in IE from the user (using IE
to start Google Maps and getting a lat/long point), process the data
in the script, change a few values in IE and trigger a function to
set up for more input (AFAIK it can't be done by dynamic HTML, it
won't trigger Google Maps). [and no the script
can't all be embedded in IE, it also uses WSH functions]

The way it currently works is in IE I define a hidden field (the value
is used for IE to signal vbs, the on click function is exposed for vbs
to signal IE)
<INPUT TYPE="hidden" ID="OK" NAME="OK" VALUE="0" OnClick="dosomething
()">

To get IE to talk to the vbs, the vbs spins:
----
set elem=objIE.document.getElementById("OK")
do while elem.value=0
sleep 200
loop
----
and IE sets OK to something other than zero when the user has
completed input. This is mildly inelegent but I don't think it is non
standard and will continue to be supported in IE so if no-one has a
more elegant solution then "if it ain't broke, don't fix it"

To get vbs to talk to IE

In vbs
----
' Signal we made a change
set elem=objIE.document.getElementById("OK") ' repeated here for
clarity
elem.click
----
This worries me is I don't think the use of onclick on a hidden field
is supported by the DOM (but works in my version of IE). Ideally,
there would be a way for vbs to
discover the function dosomething() and call it directly but I don't
know how. The available documentation on the web is huge, obscure and
uninformative [well, to me who started using vbscript 3 months ago and
just started on jscript]. Is there a more elegant and/or more
standard way?

PS I posted this on microsoft.public.windows.inetexplorer.ie6.browser
but little joy. Thought this group might be a better bet.

My System SpecsSystem Spec
Old 02-08-2009   #2 (permalink)
Joe Fawcett


 
 

Re: IE automation question

I'm not sure I follow entirely but you can check the document and browser
readyState to see what stage it's at. You can also execute functions, they
are attached to the window object. So if you have a function named doThis
you can write:
Call window.doThis()

(Not tried in VBScript but works when automating from JavaScript)
You can also look at the methods of the IWebBrowser2 interface for more
ideas.
http://msdn.microsoft.com/en-us/libr...27(VS.85).aspx


--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

"MIS42N" <ajcashin@xxxxxx> wrote in message
news:d1699011-beaa-45af-94e2-a8226effc311@xxxxxx
Quote:

> I am driving IE from an external vbscript (cscript xxx.vbs). I can
> make IE do everything that I want, but the VBS<->IE communication
> isn't very elegant and it's probably
> non standard. Is there (i) a way to to suspend a script until IE
> wakes it, and (ii) a way to get vbs to trigger an IE function
> directly?
>
> What the script does is get some input in IE from the user (using IE
> to start Google Maps and getting a lat/long point), process the data
> in the script, change a few values in IE and trigger a function to
> set up for more input (AFAIK it can't be done by dynamic HTML, it
> won't trigger Google Maps). [and no the script
> can't all be embedded in IE, it also uses WSH functions]
>
> The way it currently works is in IE I define a hidden field (the value
> is used for IE to signal vbs, the on click function is exposed for vbs
> to signal IE)
> <INPUT TYPE="hidden" ID="OK" NAME="OK" VALUE="0" OnClick="dosomething
> ()">
>
> To get IE to talk to the vbs, the vbs spins:
> ----
> set elem=objIE.document.getElementById("OK")
> do while elem.value=0
> sleep 200
> loop
> ----
> and IE sets OK to something other than zero when the user has
> completed input. This is mildly inelegent but I don't think it is non
> standard and will continue to be supported in IE so if no-one has a
> more elegant solution then "if it ain't broke, don't fix it"
>
> To get vbs to talk to IE
>
> In vbs
> ----
> ' Signal we made a change
> set elem=objIE.document.getElementById("OK") ' repeated here for
> clarity
> elem.click
> ----
> This worries me is I don't think the use of onclick on a hidden field
> is supported by the DOM (but works in my version of IE). Ideally,
> there would be a way for vbs to
> discover the function dosomething() and call it directly but I don't
> know how. The available documentation on the web is huge, obscure and
> uninformative [well, to me who started using vbscript 3 months ago and
> just started on jscript]. Is there a more elegant and/or more
> standard way?
>
> PS I posted this on microsoft.public.windows.inetexplorer.ie6.browser
> but little joy. Thought this group might be a better bet.


My System SpecsSystem Spec
Old 02-08-2009   #3 (permalink)
Tom Lavedas


 
 

Re: IE automation question

On Feb 8, 5:13*am, MIS42N <ajcas...@xxxxxx> wrote:
Quote:

> I am driving IE from an external vbscript (cscript xxx.vbs). *I can
> make IE do everything that I want, but the VBS<->IE communication
> isn't very elegant and it's probably
> non standard. *Is there (i) a way to to suspend a script until IE
> wakes it, and (ii) a way to get vbs to trigger an IE function
> directly?
>
> What the script does is get some input in IE from the user (using IE
> to start Google Maps and getting a lat/long point), process the data
> in the script, change a few values in IE and trigger a function to
> set up for more input (AFAIK it can't be done by dynamic HTML, it
> won't trigger Google Maps). *[and no the script
> can't all be embedded in IE, it also uses WSH functions]
>
> The way it currently works is in IE I define a hidden field (the value
> is used for IE to signal vbs, the on click function is exposed for vbs
> to signal IE)
> <INPUT TYPE="hidden" ID="OK" NAME="OK" VALUE="0" OnClick="dosomething
> ()">
>
> To get IE to talk to the vbs, the vbs spins:
> ----
> set elem=objIE.document.getElementById("OK")
> do while elem.value=0
> sleep 200
> loop
> ----
> and IE sets OK to something other than zero when the user has
> completed input. *This is mildly inelegent but I don't think it is non
> standard and will continue to be supported in IE so if no-one has a
> more elegant solution then "if it ain't broke, don't fix it"
>
> To get vbs to talk to IE
>
> In vbs
> ----
> ' Signal we made a change
> set elem=objIE.document.getElementById("OK") ' repeated here for
> clarity
> * * elem.click
> ----
> This worries me is I don't think the use of onclick on a hidden field
> is supported by the DOM (but works in my version of IE). *Ideally,
> there would be a way for vbs to
> discover the function dosomething() and call it directly but I don't
> know how. *The available documentation on the web is huge, obscure and
> uninformative [well, to me who started using vbscript 3 months ago and
> just started on jscript]. *Is there a more elegant and/or more
> standard way?
>
> PS I posted this on microsoft.public.windows.inetexplorer.ie6.browser
> but little joy. *Thought this group might be a better bet.
There are three examples here that do much of what you are requesting:

http://web.archive.org/web/200710210.../tglbatch/wsh/

Look at the MsgBox replacement, the Password input dialog and the
Select from a list example for most of what I know about this
subject. These use differing approaches to stay connected to the IE
part of the application. They're not perfect or exhaustive, but might
give another view and some insight into the subject.

These are from a website I maintained for a number of years, but which
I felt was too out of date to continue. Fortunately, there are people
who archive stuff off the net ;-)

Tom Lavedas
=========
My System SpecsSystem Spec
Old 02-08-2009   #4 (permalink)
ekkehard.horner


 
 

Re: IE automation question

MIS42N schrieb:
Quote:

> I am driving IE from an external vbscript (cscript xxx.vbs). I can
> make IE do everything that I want, but the VBS<->IE communication
> isn't very elegant and it's probably
> non standard.
[...]
Quote:

> [and no the script
> can't all be embedded in IE, it also uses WSH functions]
[...]
I beg your pardon for picking just one aspect of your more complex
problem. But not being able to use a .hta/.html script, because WScript.XXX
calls fail without the c/wscript.exe provider is a recurrent cause
of grief.

In theory (for optimists): You just need a (global) variable:

Dim WScript : Set WScript = Nothing

a class:

Class cWScript
Dim m_taOutput
Public Function initOtpTA( taOutput )
Set m_taOutput = taOutput
Set initOtpTA = Me
End Function
Public Sub Echo( sMsg )
m_taOutput.Value = m_taOutput.Value & sMsg & vbCrLf
End Sub
End Class

a control/element capable of displaying text:

...
<body onload = "onLoadBody">
<form>
<hr>
<textarea id = "taLog" cols= "80" rows = "10" wrap = "off"></textarea>
...

and an initialization:

Sub onLoadBody()
Set WScript = new cWScript.initOtpTA( document.getElementById( "taLog" ) )
End Sub

to use code with lots of 'WScript.Echo JustOneParam' without any problems.

In practice (for pessimists): 'WScript.Echo FrsParam, SecParm' will still
fail, because VBScript can't handle Functions/Subs with a varying number
of arguments. Implementation of WScript.Sleep needs shelling out to another
process (ping, custom .vbs, ...). I admit that I have no plan for
'WScript.StdErr.Readline()'. There seems to be some work ahead.

That's why I'm interested in a list of WScript features people are most
interested in.

So I'd like to ask you: Which Functions/Subs have to be added to the
(fake) cWScript class to let your script be transformed to a .hta/.html?

Thanks.

My System SpecsSystem Spec
Old 02-09-2009   #5 (permalink)
MIS42N


 
 

Re: IE automation question

Thanks for the replies. I've learned a bit more but still wondering.

On Feb 8, 11:06 pm, "Joe Fawcett" <joefawc...@xxxxxx> wrote:
Quote:

> I'm not sure I follow entirely but you can check the document and browser
> readyState to see what stage it's at.
I don't think I need to do this, as all the IE formatting and code is
in one .htm file. I do wait while <IE>.busy is true. Then the
external vbs script waits until the user has finished tinkering and
hits one of several input buttons (like QUIT, SKIP, SUBMIT) and IE
puts that as different values in one field, the vbs takes off when the
field is loaded. This works OK so I guess I'll stick with it.
Quote:

> You can also execute functions, they
> are attached to the window object. So if you have a function named doThis
> you can write:
> Call window.doThis()
I tried a few different things but none of them worked. As far as I
can tell, just saying call window.doThis() isn't going to work from an
external script, it would have to be something like:
Set IEobject = CreateObject( "InternetExplorer.Application" )
:
:
Call IEobject.document.doThis() [which doesn't work, but
something like it might...]
Quote:

> You can also look at the methods of the IWebBrowser2 interface for more
> ideas.http://msdn.microsoft.com/en-us/libr...27(VS.85).aspx
That's in the obscure category for me. Why is it they can publish
something like that with almost zero examples

On Feb 9, 5:15 am, Tom Lavedas <tglba...@xxxxxx> wrote:
Quote:

> There are three examples here that do much of what you are requesting:
>
> http://web.archive.org/web/200710210.../tglbatch/wsh/
>
> Look at the MsgBox replacement, the Password input dialog and the
> Select from a list example for most of what I know about this
> subject. These use differing approaches to stay connected to the IE
> part of the application.
I've bookmarked it. Useful stuff. But from my limited understanding
is using events attached to visible fields. This (again, as I
understand it) IS supported by the DOM, but is not supported for
hidden fields - just happens to work OK in IE6. I wonder if it will
continue to work in IE9, 10 etc

On Feb 9, 6:17*am, "ekkehard.horner" <ekkehard.hor...@xxxxxx> wrote:
Quote:

> I beg your pardon for picking just one aspect of your more complex
> problem. But not being able to use a .hta/.html script, because WScript.XXX
> calls fail without the c/wscript.exe provider is a recurrent cause
> of grief.
>
> In theory (for optimists): You just need a (global) variable:
>
> * *Dim WScript : Set WScript = Nothing
>
[snip]
Quote:

> So I'd like to ask you: Which Functions/Subs have to be added to the
> (fake) cWScript class to let your script be transformed to a .hta/.html?
The truth is I like the external script/HTML file separation of
function. The HTML is primarily concerned with data collection and
validation (and it is good at that) and the external script is
handling folder access, file processing, shell scripts and eventually
interfacing to a database (probably Access). I like your thinking but
as a jscript novice I am a bit lost in the world of constructors,
overloading and so on.

To give you some idea of where I'm coming from, I started programming
in Algol in 1967, and lived in the world of Cobol, Fortran, Basic and
assemblers (lots of them). Around the middle 80s I stopped serious
programming, and am just getting back to it again. It's a steep
learning curve.

So I might as well say what I'm trying to achieve. I'm reinventing
the wheel - the current program is to geotag and document JPG images,
storing the data in EXIF fields in the JPG files. Stage 2 is to
import the data into a database, either incrementally as new JPGs are
added, or a total rebuild of the database with data from all JPGs.
Stage 3 is searching the database and extracting subsets for viewing -
which can then be tagged and extracted as a subset. Just about all of
this is available in some form, but it doesn't seem like it is user
friendly, flexible, extensible, distributable enough for the intended
users.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Need help with powerpoint automation... VB Script
Excel does not die using automation .NET General
Powershell OLE Automation? PowerShell
Automation error 440 Vista General
Excel automation PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46