Jump to content

Running files (including .au3) from web pages (...locally)


Recommended Posts

Saw a post about this a while back but made mine a bit more flexible. This is mainly for use with intranet/local web pages:

If you want to be able to launch files (including uncompiled autoit scripts) from a link in a web page while avoiding that annoying Windows security popup, you need to do 2 things: build a launcher app and prepend your HREF filenames with 'autoit:'

Step 1:

The following code is my launcher.


#Include <Misc.au3> ; _isPressed()

if $CmdLineRaw = "" Then
    RegWrite($tkey,"","REG_SZ","URL: "&$name&" protocol")
    RegWrite($tkey,"URL Protocol","REG_SZ","")
    RegWrite($tkey&"\shell\open\command","","REG_SZ",'"'&$command&'" %1')
    $cmdlineraw = StringReplace($cmdlineraw, "autoit:", "")
    $cmdlineraw = StringReplace($cmdlineraw, "%20", " ")
    $cmdlineraw = StringReplace($cmdlineraw, "%5e", "^")
    $cmdlineraw = StringReplace($cmdlineraw, "/", "\")
    switch stringright($CmdLineRaw, 4)
        case ".au3"
            $sAutoIT = regread("HKLM\Software\Autoit v3\AutoIT", "InstallDir")
            if $sAutoIT <> "" Then
                If _IsPressed(11) Then
                    ShellExecute($CmdLineRaw, "", @ScriptDir, "edit")
                    ShellExecute($CmdLineRaw, "", @ScriptDir, "run")
                msgbox(0,stringtrimright(@scriptname,4), "AutoIT v3 InstallDir registry entry not found.  In order to run *uncompiled* (.au3) files, you must have AutoITScript installed.  Please visit autoitscript.com and download/install the engine.  Otherwise, you'll only be able to use *compiled* (.exe) addons")
        Case Else

Note: I added stringreplace() for spaces, ^, and forward slashes (some browsers convert these chars to codes...if anyone knows a better way to convert the web-friendly codes to normal chars, please let me know)

Compile the exe and then run it once...nothing visible will occur but the app will associate the 'autoit:' protocol to the launcher app.

Step 2:

Now build a webpage with a link to a file. Typically your address call would look like:

a href="c:\somefile.txt"

Prepend the file ref with 'autoit:'

a href="autoit:c:\somefile.txt"

Whenever you click on the link, it will run the launcher that will strip off the 'autoit:' part and invoke shellexecute("c:\somefile.txt") which will react as if you dbl-clicked on the file itself. Associated file types will launch the parent app. Unassociated file types will prompt for a app to run with. '.au3' files are the only special case. Links to filenames with .au3 will invoke a .au3 registry 'run' cmd (this is great if you don't wanna have to constantly compile scripts and run them straight). Holding down the CTRL key and clicking a '.au3' URL link will invoke a .au3 registry 'edit' cmd (such as loading the script into ScITe if that is how your system is set up).

This works great for me as I can now create web-based interfaces for my media suite while still being able to quickly open my scripts for editing directly from the web page I create.

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'


Link to comment
Share on other sites

It is great. I learned a lot from it. I mean eventhough I do not need to run autoit scripts from lan. But your script teaches how to set up a custom protocol. I appreciate that bit very much.

[Not using this account any more. Using "iShafayet" instead]

Link to comment
Share on other sites

  • 2 weeks later...

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

  • Recently Browsing   0 members

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