-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');

3
  • 3
    Possible duplicate of Is it possible to run an .exe or .bat file on 'onclick' in HTML Commented Jan 31, 2017 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. Commented Jan 31, 2017 at 13:55
  • 1
    don't you need to use file protocol? file:// Commented Jan 31, 2017 at 14:07

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

Can you give the code here on how to do this?? i am trying and not getting anywhere
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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.