Sign in to follow this  
Followers 0

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

5 posts in this topic

#1 ·  Posted

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.

#NoTrayIcon

#Include <Misc.au3> ; _isPressed()

if $CmdLineRaw = "" Then
    $name="autoit"
    $command=@ScriptFullPath
    $tkey="HKEY_CLASSES_ROOT\"&$name
    RegWrite($tkey)
    RegWrite($tkey,"","REG_SZ","URL: "&$name&" protocol")
    RegWrite($tkey,"URL Protocol","REG_SZ","")
    RegWrite($tkey&"\shell")
    RegWrite($tkey&"\shell\open")
    RegWrite($tkey&"\shell\open\command")
    RegWrite($tkey&"\shell\open\command","","REG_SZ",'"'&$command&'" %1')
Else
    $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")
                else
                    ShellExecute($CmdLineRaw, "", @ScriptDir, "run")
                endif
            Else
                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")
            EndIf
        Case Else
            ShellExecute($CmdLineRaw)
    EndSwitch
endif

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'

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

sounds interesting - ill try it out =)

thanks for sharing

Share this post


Link to post
Share on other sites

#3 ·  Posted

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]

Share this post


Link to post
Share on other sites

#4 ·  Posted

Hi!

See: old_message

Share this post


Link to post
Share on other sites

#5 ·  Posted

@ Michel Claveau

That's the one...I should've included a link to the originating one, my bad. Thx.


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'

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0