-3

I know there are lots of questions about this already, but i cant seem to find one that works for me.

I am trying to launch a local file from a local html using cmd to pass command to launch file but it does not seem to work.

This is what i used so far:

<script type="text/javascript" language="javascript">
function RunFile() {
window.open('C:/Windows/System32/cmd.exe /c START %temp%/file.cpl');
    }
    </script>

someone pls help with this.

Lets just asume i can do this on IE window.open('C:/Windows/System32/cmd.exe); and it will open cmd. My question is how do i pass some extra argument to make the cmd open my file from another location e.g. window.open('C:/Windows/System32/cmd.exe /c START %temp%/file.cpl');

Krets Topsey
  • 31
  • 1
  • 7
  • 3
    Possible duplicate of [Is it possible to run an .exe or .bat file on 'onclick' in HTML](http://stackoverflow.com/questions/18980957/is-it-possible-to-run-an-exe-or-bat-file-on-onclick-in-html) – JJJ Jan 31 '17 at 13:52
  • 1
    Most browsers prevent JS from opening files on the system as a security mechanism. When the file is loaded from the disk it is my understanding that the browser will allow you to open files in the directory tree of the file up to a point (in windows this might be C:/Users/Username for example), Also .cpl is not a JavaScript file and will likely fail even if it is loaded by the interpreter. – Menachem Hornbacher Jan 31 '17 at 13:55
  • 1
    don't you need to use file protocol? file:// – Raimonds Jan 31 '17 at 14:07

2 Answers2

0

You cannot run a program using a browser. You might be confused with Windows Scripting JScript, check: https://en.wikipedia.org/wiki/JScript You may run apps using that (in windows shell). Check this: https://stackoverflow.com/a/15351708/1082061

Community
  • 1
  • 1
Loksly
  • 124
  • 1
  • 4
0

You could do this using server-side binary execution on Nodejs using child_process.

Pro: Easy to use, just need a simple AJAX call to trigger execution from client to Node server.

Cons: Need to use a server instead of a single HTML page.

Community
  • 1
  • 1
Sir McPotato
  • 899
  • 7
  • 21
  • Can you give the code here on how to do this?? i am trying and not getting anywhere – Krets Topsey Jan 31 '17 at 15:04
  • Everything is detailed in the first link. Please do some reserches and challenge yourself, everythig will not be served on a plate ;) *(Anyway, I'm lacking time atm for writing a working example)* – Sir McPotato Feb 01 '17 at 08:24