Run external application with Javascript

Asked

Viewed 17,316 times

9

What code should I use to launch an external application from a computer from an HTML page?

Another time I was told that this code would be in Javascript:

var shwll = new ShellObject();
var hproc="C:\Windows\notepad.exe";
shwll.exec(hproc);

But I didn’t get any results.

  • 5

    In what environment is this code running? The ShellObject is specific to Microsoft, and I understood intended to be embedded in Visual Basic programs. There is no support for ShellObject in the browser. Security reasons... Even HTML5 - which offers multiple integration options with your environment - hasn’t gone so far as to allow access to the shell (as far as I know). Maybe you get something like this with a Java applet (Trusted), but I’m not sure.

3 answers

9

HTML is not a programming language. It is not with HTML that this is possible, but with scripting languages like Javascript and Vbscript.

With no language can you do it from a browser. The reason is security. If it were possible to run programs arbitrarily on the client machine, it would not be difficult for a hacker to force the download of malicious code to be compiled and run on his machine. At the very least you could get all the passwords stored on your computer, and in the worst case you would give access to your bank accounts to an unknown.

Windows has an executable called Wscript.exe. I will leave it to anyone who is curious to find it. This executable is capable of running Javascript locally, with administrator permissions. The environment is different from the browser - you won’t have access to many things, like Web Storage. In compensation objects such as the ShellObject become accessible, and you can even manipulate files.

I’m not an expert on Node.js, but as it is a server and not client environment, you are able to access more operating system resources with it than via browser, in a way. But I’m not sure if he’s able to access the ShellObject.

In addition to Node and Wscript, there are several other Javascript environments that allow sift through other people’s machines and destroy files access operating system components in a less restricted way than via browser. It is only a matter of searching.

Now, if the intention was really to access the shell by browser... Instead of Javascript use components WITH or Activex. And understand that this will probably only work in Internet Explorer, version 6 or lower. Good luck.

  • But depicting a topic: Type the Google site when you go to the Google Chrome installation page and you click "Download" the site does not download any file but runs a program compatible with the Framework. And Then?

  • They let you download an executable, and you have the option to save or run. Take a look at their script too to see the "magic" they do ;)

6

It is not possible, the best you can do is to explicitly ask the user by their own will to send the file to your server and you do something with it on the server. It’s a security issue. People trust what applications web They won’t put him at risk, so the software that controls this, in this case the browser, needs to guarantee it for him. And he’ll trust the navigators who do it right.

Of course it is possible through custom browsers or plugins that allow unrestricted access. But don’t count on someone installing something like this on your computer. In fact today nobody wants to install anything, even if it is reliable and only brings advantages.

In addition it is possible to use the new File API. Is not available universally (is in all relevant modern browsers) and it has several limitations. You cannot get the user file you want. Only what you yourself have produced and have access to, in addition to which you have explicit user authorization.

Execution is not among the possible activities of these files.

0

Runs in Javascript

<script>
 function Execultar(){
 var shell = new ActiveXObject( "WScript.shell" );
 shell.run( '"C:\\Windows\\System32\\notepad.exe"', 1, true );}
</script>

<a href="#" onclick="Execultar();">Iniciar</a>

Runs the notepad works on too untested Internet Explorer.

Or this way via VBS in html

<script type="text/vbscript">
    set Shell = CreateObject("WScript.Shell")
    Shell.Exec("cmd /c start notepad.exe")
</script>

Tested in Internet Explorer

I hope I’ve helped.

  • 2

    ActiveXObject only works on the Internetexplorer, which means it won’t work on browsers like Chrome, Firefox, Windows 8 Apps and MS Edge. In addition to this even if we limit the user to the use of IE still yes at most this will run an application that exists on the machine, if it does not exist there will occur any error. At most this code can be interesting as a shortcut to some Dashboard, but I don’t see any use after that. It should alert the questioner and not only give a code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.