I want to open cmd window from my web page(HTML). I'm using JS but something is not right because when i press, the function isn't called.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<script type="text/javascript">
<!--
function runCmd(mand, option)
{
var char34 = String.fromCharCode(34);
var wsh = new ActiveXObject('WScript.Shell');
if (wsh)
{
mand = 'cmd /k ' + char34 + wsh.ExpandEnvironmentStrings(mand) + ' ';
mand = mand + char34 + wsh.ExpandEnvironmentStrings(option) + char34 + char34;
if (confirm(mand))
{
wsh.Run(mand);
}
}
}
//-->
</script>
</head>
<body>
<input type="button" value="Run!" onclick="runCmd(‘notepad.exe’, ‘%programfiles%\file.txt’);" />
</body>
</html>
EDIT: I saved it as PHP and now i have an error in FF:
ActiveXObject is not defined
[Break on this error] var wsh = new ActiveXObject('WScript.Shell');
Thank you!
I want to open cmd window from my web page(HTML). I'm using JS but something is not right because when i press, the function isn't called.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
<!--
function runCmd(mand, option)
{
var char34 = String.fromCharCode(34);
var wsh = new ActiveXObject('WScript.Shell');
if (wsh)
{
mand = 'cmd /k ' + char34 + wsh.ExpandEnvironmentStrings(mand) + ' ';
mand = mand + char34 + wsh.ExpandEnvironmentStrings(option) + char34 + char34;
if (confirm(mand))
{
wsh.Run(mand);
}
}
}
//-->
</script>
</head>
<body>
<input type="button" value="Run!" onclick="runCmd(‘notepad.exe’, ‘%programfiles%\file.txt’);" />
</body>
</html>
EDIT: I saved it as PHP and now i have an error in FF:
ActiveXObject is not defined
[Break on this error] var wsh = new ActiveXObject('WScript.Shell');
Thank you!
Share Improve this question edited Nov 18, 2010 at 14:00 Ronny asked Nov 18, 2010 at 13:41 RonnyRonny 2853 gold badges4 silver badges10 bronze badges 5- In what browser? You are using IE and the page is in a trusted web site, correct? (Or whatever is needed for IE to run such potentially dangerous stuff) – Pekka Commented Nov 18, 2010 at 13:42
- in IE and FF...Yes,trusted web site. – Ronny Commented Nov 18, 2010 at 13:43
-
3
And you though that
eval()
was evil... – Ivo Wetzel Commented Nov 18, 2010 at 13:44 - 1 Firefox does not support ActiveX: support.mozilla./en-US/kb/activex – jbeard4 Commented Nov 18, 2010 at 14:04
- ohhhh....This is suck. Thank you – Ronny Commented Nov 18, 2010 at 14:07
2 Answers
Reset to default 9You will have to basically turn off all of the security features in your browser (which will need to be some variety of Internet Explorer to use ActiveX).
This kind of thing isn't allowed by most browsers, can you imagine if [random person on the internet] could run anything they wanted on your puter just by getting you to visit a web page?
According to documents :
This object is a Microsoft extension and is supported in Internet Explorer only...
the ActiveXObject
is only usable inside Internet Explorer and only with additional permissions and several warning messages. you might even consider that as it exposes client puters to several security issues, it is not supported by any other browsers.