Jump to content

Execute scripts from html


Recommended Posts

I am trying to get around a silly IE security problem when running a local hta applcation. Internet Explorer prevents any hyperlink action from automatically running an executable. For example, if you use a Javascript to run a program (script) like this... window.location.href="runit.exe";

IE will display a dialog with a title "File Download" and to get the program to run you must press the Open button. Now I thought that if the "runit.exe" program were a compiled AutoIt script, the script should be able to send keys to the dialog and press the Open button to open the program. I have tried ... ControlClick ("File Download", "", "&Open") but it does not work when the script is executed from an html page. The script does start but the ControlClick is ignored. Everything works fine when the program is called outside of IE. Does anyone have a solution to this?

Link to comment
Share on other sites

Thanks Burrup; I do use Firefox as my default browser but it won't run hta scripts.

Thanks Lazycat; I will look up LaunchinIE. It sounds like another utility I have. "Push The Freakin Button" (http://www.tlhouse.co.uk/PTFBPro) works well and there is the free version.

But none of these answer my question as to why the AutoIt script does not work. I would prefer to use an AutoIt compiled script since it would be a nice, clean solution not requiring installation.

Link to comment
Share on other sites

It sounds like another utility I have.  "Push The Freakin Button" (http://www.tlhouse.co.uk/PTFBPro) works well and there is the free version.

No, this is different behaviour. LaunchinIE not click anything, it just allow actually run any program when user click link in IE.

But none of these answer my question as to why the AutoIt script does not work. I would prefer to use an AutoIt compiled script since it would be a nice, clean solution not requiring installation.

So probably I not understand something... How your compiled script even run from html and do something if IE blocks direct running? :(

Link to comment
Share on other sites

No, this is different behaviour. LaunchinIE not click anything, it just allow actually run any program when user click link in IE.

So probably I not understand something... How your compiled script even run from html and do something if IE blocks direct running?  :(

<{POST_SNAPBACK}>

Here is an example...

Save these three scripts as files.

Compile the openchild.au3 and open test.html in IE.

test.html does run the openchild.exe, and the dialog opens, but the script does not complete, although openchild.exe works fine when run directly.

<!-- test.html -->

<HTML><BODY>

Open child.html using an AutoIt compiled executable

<p>

<input type="button" value="Open Child Page"

onclick="java script:window.location.href='openchild.exe'">

<p>

will invoke the "File Download" dialog

<p>

but the ControlFocus ControlClick does not get executed

</BODY></HTML>

<!-- child.html -->

<HTML><BODY>

You are now on the child page

</BODY></HTML>

; openchild.au3 to be compiled as openchild.exe

Run(@Comspec & " /c start " & @SCRIPTDIR & "\\child.html")

WinWaitActive("File Download","","2")

ControlFocus("File Download","","&Open")

ControlClick("File Download","","&Open","")

Link to comment
Share on other sites

...test.html does run the openchild.exe, and the dialog opens...

<{POST_SNAPBACK}>

Below is a longer version of what kanumi stated:

Try this:

load your test.html file within IE

wait for the "security" dialog box to come up

do not "answer" the "security" dialog box - just leave it there

start Windows Task Manager (or a simular utility)

look for a process named openchild.exe

I do not think that openchild.exe will be listed as running; therefore, it cannot "answer" the "security" dialog box that IE has presented.

If you find that openchild.exe is running and you have not "answered" the "security" dialog box that IE has presented... then I must not understand what you are asking about.

Again, if I understand what you are telling me that you are seeing, then the test.html page is asking you (via the "security" dialog box) if you want to run the script named openchild.exe... IE should not run the openchild script and then ask you if you want to run it.

Clear as mud?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I do not think that openchild.exe will be listed as running; therefore, it cannot "answer" the "security" dialog box that IE has presented.

This is exactly what I tried to explain!

joed

Register AutoitX.dll (bundled in the standard installer) and try this code for test.html (assume that openchild.exe and test.html in root of C:):

<HTML>
<head>
<script language="Javascript">
function RunApp(app) 
{
var oAutoIt = new ActiveXObject("AutoItX3.Control");
oAutoIt.Run(app)
}
</script>
</head>

<BODY>
Open child.html using an AutoIt compiled executable
<p>
<input type="button" value="Open Child Page"
onclick="javascript:RunApp('c:\\openchild.exe')">
<p>
will invoke the "File Download" dialog
<p>
but the ControlFocus ControlClick does not get executed
</BODY></HTML>

But imo in this case simpler to place all "openchild.au3" code into page...

Link to comment
Share on other sites

The first time that I read this thread, I did not see these two posts:

Lazycat (Posted May 17 2005, 03:13 PM)

and the one before it---

joed (Posted May 16 2005, 07:14 PM)

Then in another session - on another computer

I noticed the post by Lazycat (Posted May 17 2005, 03:13 PM)

...and I thought how odd, that a post was made in the middle of a thread, I must have just missed it, so I looked for the post that was quoted in this mysterious "new post"

.........QUOTE(joed @ May 17 2005, 03:14 AM)........

[i could not find a post date/time match or a post text match - even used a ctrl-f search for the text.]

I now on yet another computer and I can see what I think are all of the posts for this thread. I'm going to blame those problems on the forum software, my browser or my senility... in that order :-)

All of that to say this - my post was probably a wasted repeat of previous info... :-(

(Another "post count + 1" post)

Have fun with this thread....

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

This is exactly what I tried to explain!

joed

Register AutoitX.dll (bundled in the standard installer) and try this code for test.html (assume that openchild.exe and test.html in root of C:):

<HTML>
<head>
<script language="Javascript">
function RunApp(app) 
{
var oAutoIt = new ActiveXObject("AutoItX3.Control");
oAutoIt.Run(app)
}
</script>
</head>

<BODY>
Open child.html using an AutoIt compiled executable
<p>
<input type="button" value="Open Child Page"
onclick="javascript:RunApp('c:\\openchild.exe')">
<p>
will invoke the "File Download" dialog
<p>
but the ControlFocus ControlClick does not get executed
</BODY></HTML>

But imo in this case simpler to place all "openchild.au3" code into page...

<{POST_SNAPBACK}>

Thanks LazyCat and all who offered advice. You guys are great. It is very much appreciated. The above solution works well in IE.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...