Passing arguments while launching program from browser - windows

I am trying to launch an application (.exe) from my browser.
The specific app needs 4 arguments/parameters when launching, which are: firstname, lastname, id, info
Is there a way to add these arguments on the Internet Explorer address bar when i launch my program?
I mean something like this:
"myapp:// -firstname -lastname -id -info"
(I only managed to add those arguments straight to the windows registry, it worked that way. But thats no help... i need them to be inputted when launching the app )
I have added this to my windows registry:
[HKEY_CLASSES_ROOT\myapp]
#="URL:myprogram Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
#="\"C:\\myapp.exe\""
[HKEY_CLASSES_ROOT\myapp\shell]
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\vsa\shell\open\command]
#="\"C:\\myapp\" "%1"
Thanks for help already! I hope someone knows how to fix this... :)
ps. Im using windows 7 64 bit and Internet Explorer 10.

You cannot simply pass multiple command line arguments to your application (unless they're listed explicitly in the registry as you've shown).
Instead, you must code your application's executable so that it is able to process the Application Protocol URL string. So your code is invoked by the browser like so:
C:\apps\myapp.exe "myapp:myParam?myParam2&myParam3&myParam4"
The executable must be able to process this string and handle it appropriately. You must take care to avoid security holes in the parsing of this string, as ANY webpage could exploit a hole here to escape the browser sandbox and attack the user's system.
There's more information on Application Protocols in this post: http://blogs.msdn.com/b/ieinternals/archive/2011/07/14/url-protocols-application-protocols-and-asynchronous-pluggable-protocols-oh-my.aspx

Related

What does APPCOMMAND_LAUNCH_APP1 do?

See https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-appcommand for reference.
I've just made a tool to send certain button presses to Windows and I came across this 'button'. It looks like something I could use, but I can't find anything about how it works. I've already tried sending it with my tool, but nothing happens. (I am able to successfully send commands like microphone mute and media play/pause, so my implementation is correct.)
What does APPCOMMAND_LAUNCH_APP1 do? What is app1 or how can I configure what app1 should be?
As Jimi said in the comments, the app1 and app2 applications are defined in the registry. By default it should be Windows Explorer for app1 and Calculator for app2, but it can be modified.
The registry key where these applications can be viewed / redefined is here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey
The numbered keys in AppKey correspond to the command number of the WM_APPCOMMAND sent.
The value may be something like calc.exe if the application can be found in the PATH environment variable, but it may be the path to an executable as well. Even some special commands are supported that Windows will recognize as special folders. See https://www.autohotkey.com/docs/misc/CLSID-List.htm for special folder GUIDs.

Registering my application to URI Scheme and fetching the command that launched it

Windows allows me to register my application to a URI Scheme as defined here. If the application is already running clicking on the URI should bring it to the foreground. For some reason, GetCommandLineW() keeps giving me the original command that launched the application.
Is there some way I could get the new URI that brought my window to the foreground.
I'm aware Win messages could be used to get the command line arguments. Is there some way to associate my URI commands with a win message.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\myapp]
#="URL:myapp"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
#="<Path To App>,2"
[HKEY_CLASSES_ROOT\myapp\shell]
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\myapp\shell\open\command]
#="\"<Path To App>" \"%1\""
Firstly, thanks a lot everyone for your comments. Sorry, I'm a bit of a newbie and it took me some time to grasp what was being stated from the beginning. I'll leave this comment here in case someone wants to check back.
As suggested, my app did launch a new window. It found an instance of my app that was already running. And as a result terminated.
What I changed? Before this newly launched instance is terminated, I send a new message to the previously running instance of my application. In order to pass the contents of the command line I used named shared memory.
The receiving app just listened to this message. On receiving it, it retrieves the command line from the shared memory and allows me to handle the command line.
Thanks again.

Change start -> run -> chrome to include switches

I've looked around the internet for a way to use Windows's Windows+R shortcut to run chrome (or any app) with with default command-line switches.
My wife and I share a Windows User, but in Chrome, we have separate users so we don't have to share settings, bookmarks, etc.
Chrome has a switch --profile-directory="[someDir]" that will allow you to set the user when it's run. I'm the only one who uses the Windows+R shortcut, so I'd like to set the default setting, when I type "chrome", to run a chrome instance with my user, regardless of the last chrome window opened (which is how it decides which user to run).
It looks like the right place to make this change is in the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
If I edit the (Default) key to include --profile-directory="Default", Windows can't find the path, presumably because it puts quotes around the whole thing when I press enter on the Run dialog box.
Using something akin to SQL Injection and adding strategically placed quotes doesn't work either--my guess is that it escapes them.
MSDN hints that you might be able to add command-line parameters as subkeys to the ...\App Paths\chrome.exe key, but I tried adding --profile-directory = "Default", --profile-directory= = "Default", and --profile-directory="Default" = (empty string), none of which worked.
Anyone know how to do this, or are perhaps better at Google than I am?
As a last resort, I can replace the (Default) reg key to point to a batch file that runs chrome.exe with the switch, but I would really rather not.
It seems that you need to use the internal Chrome profile name.
I'm running ChromePortable, so the first thing I had to do was change the user-data-dir
chrome://version helps confirm the profile in use....
At first I thought a full path was required. Actually, it's just the internal name that's referenced...
Here's an example of my revised Chrome shortcut
L:\OS\MyApps\GoogleChromePortable\App\Chrome-bin\chrome.exe --user-data-dir=L:\OS\MyApps\GoogleChromePortable\Data\profile --profile-directory="Profile 1"
(as always, re command args, any spaces should be surrounded by quotes)

Bat file to open webpage with parameters to local file

Creating a bat file with:
start http://www.google.com/search?q=test
Does just what I would want it to do, it opens my default web browser (Chrome in my case) and browses to the URL http://www.google.com/search?q=test.
However, a bat file with:
start file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1
Only opens my default browser and browses to file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html
Note the lack of ?wbt=1. In order to fix this I've tried:
URL encoding the question mark
Running the start command parameters "window name" "file path in quotes"
Putting the file path in
variable and passing the variable to start
But none of those work. How can I get this to work?
I tested this and got the same result. I'm not really sure, but I guess this belongs to the question mark. The local file system of Windows can never have file names with ?, because this is a "wildcard" like *. I think it is possible that the file name is truncated there.
The following codes also doesn't work or produces only error messages:
start "file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1"
start file:///"C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1"
The best solution I've come up with so far is:
powershell -noprofile -command "[void][System.Diagnostics.Process]::Start('chrome', 'file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1')"
This solution has the batch file launch PowerShell and then use the .NET System.Diagnostics.Process.Start method to launch Chrome with the correct parameter. The only downside is that it makes a browser choice for me and I'd prefer it to use my default browser, but I can live with that. I'll accept another answer (that is not much more complex) that uses the default browser.

How to launch an application from a browser?

Is it possible to launch an application from a browser? I am not talking about opening a file from a browser (like open a PDF with Adobe Reader), but rather opening a new (blank) instance of an application that is installed on the user's machine.
Hypothetical situation: User browses a website that lists computers that can be managed via RDP. He clicks on a link to 192.168.1.10, that link opens Microsoft RDP client (mstsc.exe) with that ip address already filled out.
I am talking strictly about Windows universe.
Is that thing even doable outside of ActiveX and IE?
Is it wise to attempt this in IE with ActiveX?
The correct method is to register your custom URL Protocol in windows registry as follows:
[HKEY_CLASSES_ROOT\customurl]
#="Description here"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\customurl\shell]
[HKEY_CLASSES_ROOT\customurl\shell\open]
[HKEY_CLASSES_ROOT\customurl\shell\open\command]
#="\"C:\\Path To Your EXE\\ExeName.exe\" \"%1\""
Once the above keys and values are added, from the web page, just call "customurl:\\parameter1=xxx&parameter2=xxx" . You will receive the entire url as the argument in exe, which you need to process inside your exe. Change 'customurl' with the text of your choice.
You can't really "launch an application" in the true sense. You can as you indicated ask the user to open a document (ie a PDF) and windows will attempt to use the default app for that file type. Many applications have a way to do this.
For example you can save RDP connections as a .rdp file. Putting a link on your site to something like this should allow the user to launch right into an RDP session:
Server 1
#AbhijithCR 's reply works well. To register the protocol via a .bat file, do something like this
set key=customurl
reg add HKCR\%key% /ve /d "URL:Description"
reg add HKCR\%key% /v "URL Protocol" /d ""
reg add HKCR\%key%\shell
reg add HKCR\%key%\shell\open
reg add HKCR\%key%\shell\open\command /ve /d ""c:\path to\your.exe" ""%%1"""
For me getting all the quotes and the double percent signs right was the tricky part.
Some applications launches themselves by protocols. like itunes with "itms://" links. I don't know however how you can register that with windows.
We use a sonicwall vpn. It launches a java applet that launches mstc with all the credentials setup. You really can't do this without a java applet or activex plugin.
Microsoft uses this technique itself on their small business server for getting inside the network. I wouldn't say it is a terrible idea, as long as platform independence isn't important.
You can use SilverLight to launch an application from the browser (this will work only on IE and Firefox, newer versions of chrome don't support this)
Example code here
I achieved the same thing using a local web server and PHP. I used a script containing shell_exec to launch an application locally.
Alternatively, you could do something like this:
Notepad

Resources