How to run .exe file or .bat file based on button click event using Javascript
Just save this code as RunExe.hta and not RunExe.html and executes it by double click on it !
EDIT : REMARK about (HTA) (HTML Application)
HTML Application (HTA) is a Microsoft Windows program whose source code consists of HTML, Dynamic HTML, and one or more scripting languages supported by Internet Explorer, such as VBScript or JScript.
The HTML is used to generate the user interface, and the scripting language is used for the program logic.
A HTA executes without the constraints of the internet browser security model; in fact, it executes as a "fully trusted" application.
further reading about HTA HTML Application
<html>
<head>
<title>Run Exe or Bat files from HTA by Hackoo</title>
<HTA:APPLICATION
APPLICATIONNAME="Run Exe or Bat files from HTA by Hackoo"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>
<script>
function RunExe(){
var shell = new ActiveXObject("WScript.Shell");
var path = '"S:/Test.bat"';
shell.run(path,1,false);
}
</script>
<input style="width: 170px; height:23px; color: white; background-color: #203040;
font-family:Book Antiqua;" type="button" Value="Temperature Sensor" onClick="RunExe();"
</html>
Is it possible to run an .exe or .bat file on 'onclick' in HTML
Here's what I did. I wanted a HTML page setup on our network so I wouldn't have to navigate to various folders to install or upgrade our apps. So what I did was setup a .bat file on our "shared" drive that everyone has access to, in that .bat file I had this code:
start /d "\\server\Software\" setup.exe
The HTML code was:
<input type="button" value="Launch Installer" onclick="window.open('file:///S:Test/Test.bat')" />
(make sure your slashes are correct, I had them the other way and it didn't work)
I preferred to launch the EXE directly but that wasn't possible, but the .bat file allowed me around that. Wish it worked in FF or Chrome, but only IE.
Is it possible to run a .bat file on button click with node
i figured out how to solve my problem
function Process() {
const process = require('child_process');
var ls = process.spawn('script.bat');
ls.stdout.on('data', function (data) {
console.log(data);
});
ls.stderr.on('data', function (data) {
console.log(data);
});
ls.on('close', function (code) {
if (code == 0)
console.log('Stop');
else
console.log('Start');
});
};
document.getElementById('buttonid').addEventListener('click', function(e) {
Process();
console.log("working");
});
Related Topics
How to Change the Href Attribute For a Hyperlink Using Jquery
Creating a Textarea With Auto-Resize
Converting HTML String into Dom Elements
What Is the Htmlspecialchars Equivalent in JavaScript
How to Programmatically Tell an HTML Select to Drop Down (For Example, Due to Mouseover)
How to Know Which Radio Button Is Selected Via Jquery
Jquery Id Selector Works Only For the First Element
What's the Effect of Adding 'Return False' to a Click Event Listener
Clearing ≪Input Type='File' /≫ Using Jquery
How to Store an Array in Localstorage
How to Stop Event Propagation With Inline Onclick Attribute
Set the Value of an Input Field
Using an HTML Button to Call a JavaScript Function
Why Js Function Name Conflicts With Element Id
Do You Need Text/JavaScript Specified in Your ≪Script≫ Tags
Should I Write Script in the Body or the Head of the Html