Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Application URL - Launch local application from browser


  • Please log in to reply
15 replies to this topic
jsherk
  • Members
  • 65 posts
  • Last active: Jul 02 2014 12:27 PM
  • Joined: 11 Jun 2011
Application URL is a trick so that you can launch any application on your local computer from your browser.

I tested this on Win XP Pro with Google Chrome v14, Chromium v16, Internet Explorer v7, Firefox v6.

Both Chromium and Google Chrome do not allow the browser or it's extensions to access local files, so you cannot create an extension that would call a program already on your machine. The exception is using an NPAPI plugin, but nobody in the AHK forum seems to know what that is or how to do it (and neither do I), so this was the alternative that I came up with.

In order for this to work, it requires you to add a new registry key to the Windows Registry to register a new URL Protocol. I have chosen appurl:// but you can modify it to what ever you want.

Once the new URL Protocol is registered, you can type in your browser address bar:
appurl://path/to/myapp
and it will launch your application.
Or you can save it as a link in your broswer Bookmarks/Favorites.
NOTE: For Google Chrome and Chromium, the address bar trick does NOT work, but the saving it as a Bookmark does.
NOTE: For Firefox, you may have to choose the application and application directory the first time you try to do this, so pick
C:\Program Files\AutoHotKeyAppURL\appurl.exe

All the AHK script does, is remove the appurl:// part of what was passed to it, and then does Run path/to/myapp

Here is the registry file called appurl.reg
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\appurl]
@="URL:AutoHotKey AppURL Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\appurl\DefaultIcon]
@="appurl.exe,1"

[HKEY_CLASSES_ROOT\appurl\shell]

[HKEY_CLASSES_ROOT\appurl\shell\open]

[HKEY_CLASSES_ROOT\appurl\shell\open\command]
@="\"C:\\Program Files\\AutoHotKeyAppURL\\appurl.exe\" \"%1\""



Here is the AHK script called appurl.ahk
Note that I compiled it into an EXE first called appurl.exe
and then placed it in:
C:\Program Files\AutoHotKeyAppURL\appurl.exe
; Application URL v1.0 by Jeff Sherk
;
; Will run a program that you pass in as a parameter (command line argument).
; Specifically created to be used with URL Protocol appurl://
;
; EXAMPLE:
;  You can type appurl://path/to/myapp.exe in the address bar of your browser to launch the application
;
; See these threads:
;  http://www.autohotkey.com/forum/viewtopic.php?p=477917
;  http://www.autohotkey.com/forum/viewtopic.php?t=76997
;  http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
;  http://stackoverflow.com/questions/2330545/is-it-possible-to-open-custom-url-scheme-with-google-chrome
;
; Requires adding the following Registry Entry to work. You can copy and paste whats between the dashed lines
;  into a file called: appurl.reg  Just remember to remove all the semi-colons; at the beginning of the lines.
;-------------------------------------------------------------------
;Windows Registry Editor Version 5.00

;[HKEY_CLASSES_ROOT\appurl]
;@="URL:AutoHotKey AppURL Protocol"
;"URL Protocol"=""

;[HKEY_CLASSES_ROOT\appurl\DefaultIcon]
;@="appurl.exe,1"

;[HKEY_CLASSES_ROOT\appurl\shell]

;[HKEY_CLASSES_ROOT\appurl\shell\open]

;[HKEY_CLASSES_ROOT\appurl\shell\open\command]
;@="\"C:\\Program Files\\AutoHotKeyAppURL\\appurl.exe\" \"%1\""
;-------------------------------------------------------------------

if 0 != 1 ;Check %0% to see how many parameters were passed in
{
    msgbox ERROR: There are %0% parameters. There should be 1 parameter exactly.
}
else
{
    param = %1%  ;Fetch the contents of the command line argument

    appurl := "appurl://" ; This should be the URL Protocol that you registered in the Windows Registry

    IfInString, param, %appurl%
    {
        arglen := StrLen(param) ;Length of entire argument
        applen := StrLen(appurl) ;Length of appurl
        len := arglen - applen ;Length of argument less appurl
        StringRight, param, param, len ; Remove appurl portion from the beginning of parameter
    }

    Run, %param%

}

Here are a couple extra links with helpful information:
<!-- m -->http://msdn.microsof...ibrary/aa767914<!-- m -->
<!-- m -->http://stackoverflow... ... gle-chrome<!-- m -->

Hope this is helpful to somebody!

Thanks

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I'm wondering if you know of an AHK function to convert from a url to a conventional local path string?

IOW, if I have a URL like "file:///c/Program%20Files/My%20 Program/prog.exe" it would be convenient to have a func that spit out C:\Program Files\My Program\prog.exe.

Guess if I was a regex wiz I could figure it out but patterns aren't my strong point. :)

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

I'm wondering if you know of an AHK function to convert from a url to a conventional local path string?

IOW, if I have a URL like "file:///c/Program%20Files/My%20 Program/prog.exe" it would be convenient to have a func that spit out C:\Program Files\My Program\prog.exe.

Guess if I was a regex wiz I could figure it out but patterns aren't my strong point. :)


That would be possible. What should happen when you click a link? It's opened in explorer? Just pass the input parameter to a script and parse it as you wish. The input parameter is anything that is behind the "uri:", for example I use it in Appifyer in the form of "Appify:Colorette", which will run the predefined program (in my case Appify.exe) and pass Colorette as the first input parameter.

jsherk
  • Members
  • 65 posts
  • Last active: Jul 02 2014 12:27 PM
  • Joined: 11 Jun 2011
Modifying my script above, you get something like this, which will remove the file:// part.
    param := ""
    appurl := "file://"

    IfInString, param, %appurl%
    {
        arglen := StrLen(param) ;Length of entire argument
        applen := StrLen(appurl) ;Length of appurl
        len := arglen - applen ;Length of argument less appurl
        StringRight, param, param, len ; Remove appurl portion from the beginning of parameter
    }

    msgbox %param%


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I'm wondering if you know of an AHK function to convert from a url to a conventional local path string?

IOW, if I have a URL like "file:///c/Program%20Files/My%20 Program/prog.exe" it would be convenient to have a func that spit out C:\Program Files\My Program\prog.exe.


URL := "file:///C:/Program%20Files/My%20Program/Prog.exe"
MsgBox,% PathCreateFromURL( URL )

PathCreateFromURL( URL ) {
 VarSetCapacity( fPath, Sz := 2084, 0 )
 DllCall( "shlwapi\PathCreateFromUrl" ( A_IsUnicode ? "W" : "A" )
         , Str,URL, Str,fPath, UIntP,Sz, UInt,0 )
Return fPath
}



jsherk
  • Members
  • 65 posts
  • Last active: Jul 02 2014 12:27 PM
  • Joined: 11 Jun 2011
Thanks SKAN!

Is there a list of DllCall functions that can be called?

Thanks

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Is there a list of DllCall functions that can be called?


I know only this one, but it is outdated: <!-- m -->http://www.activevb.... ... ereng.html<!-- m -->

jsherk
  • Members
  • 65 posts
  • Last active: Jul 02 2014 12:27 PM
  • Joined: 11 Jun 2011
i will check it out

thanks

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
@jsherk, I didn't mean to hijack your thread. But when you are doing something related often you learn quite a bit in that area. So I hoped you wouldn't mind.

@SKAN thanks for the function.

:D

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I have some Explorer utilities that watch the active window and add folders to an MRU list. One thing I did find was that the Shell.Application approach was fine for hotkeying on a window. But it's not ideal for polling.

I reverted to the old get window text method that requires Show Full Path in Address Bar. Otherwise the user may close the window before it's detected.
There must be a greater lag time using the shell object would be my guess.

I was hoping to get away from that requirement but it looks like I'm stuck with it. :)

But it works fine with the hotkey approach. For example I have a New Folder hotkey and the function gets the folder name without issue.

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


nook
  • Members
  • 2 posts
  • Last active: Oct 17 2011 07:54 AM
  • Joined: 13 Oct 2011
Hi.

I'm building an installation and need to simulate a mouse click in chrome browser. I've understood this can be accomplished through an AutoHotkey script.

But, I need to execute the script from the browser. It looks to me that using the method in this post could be a solution. However, I am not exactly sure how to do it. I don't know how to compile a AHK-script into an exe file for one.

So I don't need to be able to run any application, just to execute one script.

Could you please give me some step by step directions on how to accomplish this. It would be highly appreciated!

cheers

nook
  • Members
  • 2 posts
  • Last active: Oct 17 2011 07:54 AM
  • Joined: 13 Oct 2011
Problem solved.

Installed a web server on the computer that allowed med to run the ahk script from php.

Youdhbir
  • Guests
  • Last active:
  • Joined: --
Thanks for the solution. It worked !

Rytis
  • Members
  • 1 posts
  • Last active: Aug 01 2014 05:11 AM
  • Joined: 30 Jul 2014

Hi,

Firstly I am sorry for my english language skills :) 
I want to ask you  if it is possible that Google Chrome browser open executable file itself without java applet help? 
Now, I have software where in browser I press the button word document is opened. but it is opened with java applet help. Can somehow Chrome do this without java applet help? Thanks for your answers.



samplist
  • Members
  • 1 posts
  • Last active: Aug 27 2014 04:21 PM
  • Joined: 27 Aug 2014

Looking for the same thing i've found WebRun software that launches any local application from browser.

Although I couldn't manage to make jsherk's post to work, WebRun worked perfectly with no hassle at all!

So for anyone looking to run local apps from html links, WebRun works great.