Hyperlink to launch client's local executable program with parameters

Mr_Peerapol
Mr_Peerapol used Ask the Experts™
on
Hi all experts,

I'd like to know how to create a hyperlink (javascript or other techniques are also welcome) so that when client clicks on the link, web browser (only IE is fine, but working for all browsers is excellent) will luanch a local executable program located in the client machine with parameters. No executable files are in the server. All executable files are in the client machines.

For example:
C:\Program Files\MyApp\MyApp.EXE -Param1 15 -Param2 20


Thanks,
-MP
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You would need something like Citrix to do this. For security reasons, you can't run exe's on the client machine from a browser.

Commented:
just a random thought though... you might be able to get them to download a .bat file which runs the program and tell them to select "open" instead of "save". I've never tried it though, so I can't guarantee it will work.
You can create a DLL file to embed in your page, to execute the program wanted. If you want me to I can create it for you.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Commented:

<a href="javascript:LaunchApp()">Launch the executable</a>

<script>
function LaunchApp() {
 if (!document.all) {
  alert ("Available only with Internet Explorer.");
  return;
 }
 var ws = new ActiveXObject("WScript.Shell");
 ws.Exec("C:\\Program Files\\Adobe\\Photoshop 6.0\\Photoshp.exe");
}
</script>

Only IE has support for ActiveX, so this won't work in any other browser. The user must answer "YES" to a warning that the page is trying to execute ActiveX code.

C:-)
The user must have photoshop too :-P

good code!

Commented:
Additionally, the ws.Exec command is available only in Windows Script Host 5.6 which is standard in Win 2k and XP, but not in earlier versions.

Alternatively, if you use for example,
location.href = "C:\\Program Files\\Adobe\\Photoshop 6.0\\Photoshp.exe";

the browser will give a file-download dialog to which the user must choose "Open".


C:-)
location.href = "C:\\Program Files\\Adobe\\Photoshop 6.0\\Photoshp.exe";

That sucks

Commented:
Pizza - your attitude is extremely childish. We should be able to air alternatives without insulting each other.

c:-)
[[just a random thought though... you might be able to get them to download a .bat file which runs the program and tell them to select "open" instead of "save". I've never tried it though, so I can't guarantee it will work. ]]

Has been said before....

as an addition to this:
[[client machine with parameters.]] - You can't send parameters in the example you gave last.

And as an addition to that;
I complemented you with the activeX "Wscript.Shell" example, which really was nice.

And as of the childish part you are talking of, you are the only one ending every post with c:-) which has a, softly said, little bit of a childish expression.

And please call me by my complete name as I would also do to you jsCraig.

IF you have access to each client to add a regsitry key you can do what you want seamlessly ...
To execute c:\my prog\prog.exe %a %b %c

Add to a new key to HKEY_CLASSES_ROOT called 'myprog'
Add an empty string to this key called 'URL Protocol'
Add the sub-keys:  \shell\open\command
Set the value of the default string inside the command key to: " c:\my prog\prog.exe %1"

On your web page have your link as:
<A HREF="myprog: %a %b %c">run myprog</A>
And that's not insulting you; it is insulting the method you describe:

location.href = "C:\\Program Files\\Adobe\\Photoshop 6.0\\Photoshp.exe";

Which doesn't look nice, on the browser.
Top Expert 2006

Commented:
Is it your own program? If yes, you can make entries in the registry during install time for a document and content type the way entries are made for excel/word/realplayer programs. Then the link can simply send a small test file with content type set to your program. The browser will launch your program without asking the user anything (default settings).

If it is not your program but you know it is similar to excel/word/realplayer, you can send a small text file with the content type set to the program's content type. However not all programs make those entries. What is the program that you want to launch?

In both these cases the href doesn't point to the program but it points to a document about which the browser knows. The browser launches that program and passes the filename as argument. You would have seen it for word/excel and mostly for real player links. The link points to .ram/.rm document and not to the real player itself but the browser knows how to handle those links. In all these programs 4-5 entries (per document type) are made in the registry during the install process. I don’t remember the exact entries but I have those somewhere and can locate those, if you are interested.
[[MyApp.EXE ]] I think it is his own app. So he only has to add the mime type to the registry in the installation process. good point!

Author

Commented:
First of all, thank you all for your help so far.

miskate,
What is 'citrix' ?

pizzametsalami,
I do want that ActiveX for sure since users will not be asked with the warning messages after the component installed. I can open another thread and give you additional points. Thanks in advace :-)

jsCraig,
I'm using W2K Professional. After I chose 'Yes' when asked, the script generated an error at this line:
ws.Exec("C:\\Program Files\\Adobe\\Photoshop 6.0\\Photoshp.exe");
The error is 'Object doesn't support this property or method'.
What should I do ?

clivewall,
This is a good comment also. However, I have many applications. So I just don't want to do that way.

amit_g,
Some of them are my programs, some are not.

-MP
Commented:
Try this


<script>
var fso = new ActiveXObject("Scripting.FileSystemObject");
var wScriptVer = fso.GetFileVersion(fso.GetSpecialFolder(1)+"\\wscript.exe");
alert (wScriptVer);
</script>

which will show the version number of your machine's WSCRIPT.EXE

Sorry, I've doublechecked and discovered I was wrong about win 2k ...

This is a quote from the Windows Script documentation:

Windows Script Host is built into Microsoft Windows 98, 2000, and Millennium Editions. If you are running Windows 95, you can download Windows Script Host 5.6 from the Microsoft Windows Script Technologies Web site (http://msdn.microsoft.com/scripting).

Note   You can also go to the web site listed above to upgrade your current engines. The version of WSH in Windows 98, 2000, and Millennium Editions is either version 1.0 or 2.0. You must upgrade to version 5.6 to get the new features.

C:-)
I do want that ActiveX for sure since users will not be asked with the warning messages after the component installed. I can open another thread and give you additional points. Thanks in advace :-)

>>

Well it is possible that a popup telling you that running activeX components on websites is a potentional danger shows up, but I don't think that can be prevented. I'll work on it.
If you are using .NET it is easy. Just place this file in the correct folder at the server, call it for instance executor.aspx. Remember to “SetCurrentDirectory” to the actual path.

I use it regularly to unzip files at the server, - by a power of degree faster than FTP. You also get the results back in the browser, just as you were executing from the command line.


<% @Page Language="C#" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Text" %>
<% @Import Namespace="System.CodeDom.Compiler" %>
<% @Import Namespace="System.Diagnostics" %>
<script language="C#" runat="server">

// execute an application, return output string
// use for instance to unpack zip files on the server
string ExecuteCmdLineApp(string strCmd)
{
  string output = "";
  string error  = "";

  Directory.SetCurrentDirectory("<path to your dir on the server>");
  TempFileCollection tf = new TempFileCollection();
  Executor.ExecWaitWithCapture(strCmd, tf, ref output, ref error);

  StreamReader sr = File.OpenText(output);
  StringBuilder strBuilder = new StringBuilder();
  string strLine = null;

  while (null != (strLine = sr.ReadLine()))
  {
    if ("" != strLine)
    {
      strBuilder.Append(strLine);
      strBuilder.Append("\r\n");
    }
  }
  sr.Close();

  File.Delete(output);
  File.Delete(error);

  return strBuilder.ToString();
}

void btnSubmit_Click(Object Sender, EventArgs E)
{
  string strResult = "Error";
  try
  {
    strResult = ExecuteCmdLineApp(txtCommand.Text);
  }
  catch(Exception e)
  {
    strResult = e.ToString();
  }
  txtResult.Text = strResult;
}

</script>

<form runat="server" method="post">
Kommando: <asp:TextBox id="txtCommand" runat="SERVER" value="ping localhost" size=30 />
<asp:Button id="btnSubmit" text="Execute command"
    onClick="btnSubmit_Click"
    runat="server" />

<pre>
<asp:Label id="txtResult" runat="server" />
</pre>

</form>
Sorry I was to fast! :)

Author

Commented:
rolftollerud,
Thank you too, but I'm not asking how to run an application at the server :-)
I just want to launch an application which is already installed in the client machine.

pizzametsalami,
>>it is possible that a popup telling you that running activeX components on websites is a potentional danger shows up, but I don't think that can be prevented<<
Don't worry. That's fine.

jsCraig,
I'm testing it. Will get back to you.

Thanks,
-MP

Ok then I'll start building it :-)
Top Expert 2013

Commented:
If this is on an intranet, then all this bending around with windows shell and activeX is fine.  That is what they are for.

However if you are going across the internet with this you have more of a problem than just anlert coming up.  If your users are on corporate sites behind a decent firewall, anything that attempts to access the local hard drive will be block at the firewall; where security levels are very high like any of mine, sending a page that has these types of codes on them will not just get the page blocked, it will get the site flagged an dangerous and user will not be able to access it at all.  Many sites will not permit users to download such pages even with a cert, without specific permission.  

It is not clear to me from the question if you will be going across the Internet with it, but if you are be aware that you will limit your reach with that kind of code on your pages.

Cd&

Author

Commented:
Cd&,
Thanks. That's on only company intranet.

-MP
Top Expert 2013

Commented:
If it is Intranet then perhaps you can use IEAK handle customization of the client and client regisrty to handle it:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/policy/policy/rsop_ieak_wmi_classes_illustrated.asp

Cd&

Author

Commented:
All of you are of great help for me, thanks !

pizzametsalami,
I'm still waiting for the component.

-MP
I am working on it.... But i just saw some complications... I'll have to work them out first.
Pizzametsalami, jsCraig, and others.

I am looking for a way to do something similar to this WITHOUT customer interaction (no need to click ok, save, or open)  to make the file launch.  This is for a patch CD in response to the Blaster worm and my customers are not the type to think outside the box enough to  click open or anything like that.   I want the CD to autorun an hta (which works right now) that has links to the executables for the patches (those are there but when clicked opens a "text" version of the program in the hta window rather than executing it) that when clicked run the program like the customer had double clicked the file on the CD.   there is 200+ points in this for whoever can make it work.  link to the active question is: http://www.experts-exchange.com/Web/Web_Languages/Q_20709676.html

Commented:
I'm developing a small text intranet site for a windows network. The intranet is served as HTMLfrom a linux server to the browser.

Basically I need to create a clientside bit of script in JScript or VBscript that can use activex to display a list of the local/client installed applications (from the start menu) in the html intranet page - these displayed apps must have their original icons and be clickable in order to launch the applications.

Now I know that apps can be launched with active x, I know that activex can automagically find the system special folders like start menu, but how would I retrieve all the program shortcuts and display them in the html page?

Please be a detailed as possible, and as quick as possible if you can, I'm very short on time with this now and need to find a solution. If you guys know any better solutions then please let me know them too.

Thanks guys,

Jon
Top Expert 2013

Commented:
I suggest you post a question.

You are not going to get much help by tacking on to the end of a question that was close dmore than 6 months ago.

Cd&
How do u put a dll in a page????

:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial