EXE from JavaScript [duplicate] - javascript

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I run a program or batch file on the client side?
I am new to JavaScript. I am trying to execute an EXE file from JavaScript on the web browers. How can it be done with simple code?

That is not possible due to security reasons. Imagine you are trying to access the file system of the client.

This is usually disallowed due to security reasons, if you absolutely need to do this then you have a few options however:
Prompt the user to download and run the executable
Use the WScript.Shell object
See this question for details on how to do this.
Note that this almost certainly won't work on most browsers unless your site has been placed into some sort of "trusted" zone (which may be the case if you are developing an intranet application or running inside a Html Application / .hta)
Use an ActiveX control (this will also require elevated permissions, however it is more likely that you will at least be able to prompt the user for permissions)
All 3 of these options require trust to be granted by the user (they will either have to have placed your page / site into a certain trust level, or they will have to have clicked on some sort of "trust this site" / "download this file" dialog.
(Also note that all of these options are speicfic to the Windows operating system)

As sAc says, it's not possible to directly run an exe file, though you may want to look into Google NaCl if you wish to do native code execution in a web browser. Also, please note that exe is a Windows format, and it would be very uninterpretable with other OSes and detrimental to the open web if you could run them through a browser.

It is possible if you lower the security level on your browser ..BUT that's not a good idea!
for example, in IE you can do this:
write a run function:
function run(file) {
var ws = new ActiveXObject("WScript.Shell");
ws.run(file);
}
and then for example: ....
onclick = run("file:///C:/Program%20Files/My%20Documents/yourFile.exe")

Related

How browser open a desktop application? [duplicate]

I need to launch program from browser(like battlefield when you see dialog with confirmation of starting app). Should I make an extension or there is native way to do it with javascript?
If the basic idea is to launch a desktop app from the web browser, the first step is to create a new Registry in Windows and path a URL Custom protocol. And if you need it you can also send parameters by changing console arguments in your app and append the parameters in your html file.
You can check here:
https://weblogs.asp.net/morteza/How-to-run-a-desktop-application-from-a-web-page
check out: Running .exe from Javascript
There are cross-browser compatibility issues with executing a .EXE on a clients machine. i would suggest you look into alternative languages such as Java or even Flash. But it can be done in Javascript.
-normally i wouldn't answer a question like this, but i saw someone say it's not possible. ANYTHING is possible.

How do you detect if firefox DevTools is open? [duplicate]

This question already has answers here:
How to detect if browser console / inspector is *open*?
(3 answers)
Closed 3 years ago.
I've been searching high and low but all I could find are ways to detect chrome Dev Tools and FireBUG Dev Tools. Is there a way to detect, on Firefox, that the Inspect Element/console/Dev Tool is open?
It is impossible to actually hide your client side source code without actually removing said code from being accessed client side. The simple reason for this is the fact that the code has to be downloaded to the client for it to be used. Once downloaded, it's visible to the user. No exceptions. You can do things like 'security through obscurity', but that too is not going to prevent people from downloading/viewing the source. It's just going to make the code harder to read.
If you want to prevent users from seeing your code, you're basically forced to handle the parts of the code you wish to hide server side. This way, only the input and output are visible to users, while hiding the logic that processes it.
There are some other tricks you could potentially do to make it harder to acces your code (not impossible by a long shot), but I wouldn't recommend those either. Those are usually reliant on browser security settings, easily prevented through broswer add-ons, etc.
If instead you want to prevent users from seeing your code, because you're handling security sensitive operations client side, I suggest you go back to web development 101 and check why that's an inherently bad idea.
EDIT: To purely detect if DevTools is open, you can use this: https://github.com/sindresorhus/devtools-detect and simply follow the readme.

How can I create a file using pure JavaScript?

I Got this code to create a file using JavaScript.
function WriteToFile()
{
var txt = new ActiveXObject("Scripting.FileSystemObject");
var s = txt.CreateTextFile("11.txt", true);
s.WriteLine('Hello');
s.Close();
}
WriteToFile();
it is working fine with IE but not Working in Chrome and Firefox.
usually the error is ReferenceError: ActiveXObject is not defined
is there any alternate to create file in javascript, instead of ActiveXobject(Scripting.FileSystemObject") ?
This isn't possible. At least not in pure JavaScript anyway, ActiveX objects are part of the Windows/IE thing and are NOT in the ES6 spec (http://www.ecma-international.org/ecma-262/6.0/index.html), which is why they're not supported in Chrome or Firefox.
If you wish to write JavaScript programs that can create files on the users local file system you're going to need to write a client side app, such as a chrome app (https://developer.chrome.com/apps/api_index) or write your program using Electron shell(http://electron.atom.io/).
However, if what you want is a cross browser solution to create files at specific locations on a user file system, it's just not really natively possible.
Sure browser plugins exist, but you'd need every user to install the plugin, so that's not exactly practical. For security reasons websites aren't allowed to read the users hard drive, and this is a good thing!

How to access file system in os by IE 7, and 8 browser ,without using ActiveXObject?

How to create a file or list the files in the folder in java script in IE7 and IE8.In general to access the file system in OS , java script uses ActiveXObject. But I need to access the file system not by ActiveXObject but by any other ways.
If I use ActiveXObject for access means,whenever access going to be happen each time a pop-up will appear that asks the user whether to allow or not ActiveXobject.It is little difficult one to client when dy faces this pop-up each time.
Is thr any Java script API exist to access the file system without use of ActiveXObject or any technique exist to do these things....?
I have to implement file system access applicaion in IE7 and IE8
If any one know kindly share ur knowledge.
Thanks in advance....
There are no ways in IE7/IE8 without browser plug-ins to access the local computer's file system because doing so is a major security risk and those browsers don't support any of the more modern ways of handling files.
You might get better ideas if you explain what actual problem you're really trying to solve rather than something as generic as your current question.
If this is an enterprise environment, you may be able to prewire some ActiveX settings in the enterprise browsers to allow your ActiveX plug-in to run without prompting.
Silverlight can have evaluated trust in browser applications in version 5
for First time it will ask user ( I've not tested it yet )
Notice that users must have installed Silverlight before then you can develop your own app by C#

Check if JDK is installed through javascript

The topic-title speaks for itself.
Is it possible to check if the client has JDK installed trough javascript?
I know that it is possible to check the os and the browser but is that possible too?
You can check whether the client has java enabled with window.navigator.javaEnabled().
Note that:
The return value for this method
indicates whether the preference that
controls Java is on or off - not
whether the browser offers Java
support in general.
For more information, have a look at https://developer.mozilla.org/en/DOM/window.navigator.javaEnabled
I am presuming you have an Applet or a Web Start application which you want to run.
For those cases Oracle provides the Java Deployment Toolkit JavaScript which helps to detect Java versions and also offers methods to automatically write applet tags and Web Start launcher buttons.
As you can see at http://download.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit (also contains link to downloading .js file) it can retrieve installed JREs or send the user to installation page of latest one. This might be what you are looking for.
Notes:
This applies to detecting JREs. JDKs aren't used by the browser so there isn't a need to detect them.
It might not work because of privacy settings or other browser/JRE configuration options.
I don't think you can. It would require javascript to access information beyond your browser. Maybe there's some browser specific solutions.
Its not possible to know the version of Java through javascript .If its possible then it will be a security breach.

Categories

Resources