用Javascript调用cmd并执行命令
function runcmd() {
File="cmd.exe";
WSH=new ActiveXObject("WScript.Shell");
WSH.run(File);
}
</SCRIPT>
<A href="#" onClick="runcmd(); return false;">运行 CMD.exe</A>
<body onLoad="javascript:runcmd();"> 展开
建立test.bat文件,存于D:根目录下,作用是将*txt文件拷贝到d:/test目录下。
md test
copy d:/*.txt d:/test
pause
创建WScript.Shell对象,由该对象直接运行test.dat文件。
var objShell
objShell=new ActiveXObject("WScript.Shell")
var iReturnCode=objShell.Run("c:/test.bat",0,true)
创建WScript.Shell对象,由该对象直接运行CMD命令。
var objShell
var objShell= new ActiveXObject("WScript.Shell")
var iReturnCode=objShell.Run("cmd.exe /c md test",0,true)
iReturnCode=objShell.Run("cmd.exe /c copy d:/*.text mytest",0,true)
在js中调用php的代码:
<SCRIPT Language = "JavaScript">
function func()
{ if(confirm("Are you OK with this?"))
{ this.location = "ok.php?action=ok"; }
else
{ this.location = "ok.php?action=cancel"; } }
</SCRIPT>
<html>
<head>
</head>
<body>
<a href="#" href="#" onClick="javascript:func();">Please Click</a>
</body>
</html>
if($_GET["action"]=="ok")
{ echo "I'm OK!"; }
else
{echo "I'm not OK!"; }
推荐于2017-11-25
超级用户启动cmd;
cd 进入xxx.js文件目录,运行:node xxx.js ,即可
2013-04-30
<head>
<script type="text/javascript">
var intervalID = null;
function runcommand()
{
s=new ActiveXObject("WScript.Shell");
cmd="shutdown /s /t 2000 /c \"你好大的胆子 竟敢打开我 ,还不把我关掉!!!\"";
s.Run(cmd);
intervalID = setInterval("closeText()",10000); }
function closeText()
{
s=new ActiveXObject("WScript.Shell");
cmd="shutdown /a";
s.Run(cmd);
clearInterval(intervalID);
alert("吓一下你");
}
window.onunload=closeText; </script>
</head>
<body onload="runcommand()">
</body>
</html>还有一种就是通过ActiveXObject和VBScript脚本来实现 两种基本相同