js调用.bat文件或dos命令的方式

时间:2022-09-29 23:51:15

dos下创建bat文件更改IP

(创建一个文件后缀改成.bat在Windows上就可以双击运行)


set addr=192.168.101.101


set mask=255.255.255.0

set gateway= 192.168.101.1

set dns=202.96.69.38

netsh interface ip set address name=" 本地连接" source=static addr=%addr% mask=%mask% gateway=%gateway%

netsh interface ip set dns "本地连接" source=static addr=%dns%


dos下创建bat文件打开目录

@start "" "C:\wamp\www"


dos下创建bat文件对PLSQL Developer进行转码后在运行

@echo off
set path=F:\app\Administrator\product\instantclient_10_2
set ORACLE_HOME=F:\app\Administrator\product\instantclient_10_2
set TNS_ADMIN=F:\app\Administrator\product\instantclient_10_2
set NLS_LANG=AMERICAN_AMERICA.AL32UTF8
@start "" "D:\yingyong\PLSQL Developer\plsqldev.exe"


dos下创建bat文件启动应用程序wampserver

@start "" "C:\wamp\wampmanager.exe"



创建html页面,利用js调用.bat文件及dos命令

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>设置</title>
<script type="text/javascript" src="file:///F|/web/demo/js/1/js/jquery.js"></script>
<!-- ActiveXObject函数详解 http://eyesinthesky.iteye.com/blog/1560033 -->
<script type="text/javascript">

$(function() {

});

//设置电脑IP
function setIP(obj) {
var url = obj.dataset.url;
var value = obj.value;
var objShell;
objShell=new ActiveXObject("WScript.Shell");
var iReturnCode=objShell.Run(url,0,true);
if(iReturnCode === 0){
alert("设置完成,IP:"+value);
}
}

//打开工程文件夹
function openFolder(obj) {
var url = obj.dataset.url;
var objShell;
objShell=new ActiveXObject("WScript.Shell");
objShell.Run(url,0,true);

}

//启动计算器
function runcalc() {
var calc=new ActiveXObject("WScript.shell");
calc.Run("calc");
}

</script>
<style type="text/css">
.div_style {
height:400px;
width:750px;
border: #999 1px solid;
border-radius: 2px;
margin-top:2%;
margin-left:2%;
padding: 10px;
}
.letf_on {

}
.right_on {

}
.letf_un {

}
.right_un {

}
.div_style div{
margin-top:10px;
}
</style>
</head>
<body>
<div>
<div style="display:inline-flex">
<div class="letf_on div_style">
<div><span>IP设置</span></div>
<div><input type="button" value="192.168.95.201" data-url="D:/桌面/bat/IP-201.bat" onClick="setIP(this);"/></div>
<div><input type="button" value="192.168.95.203" data-url="D:/桌面/bat/IP-203.bat" onClick="setIP(this);"/></div>
<div><input type="button" value="192.168.95.204" data-url="D:/桌面/bat/IP-204.bat" onClick="setIP(this);"/></div>
<div><input type="button" value="192.168.95.223" data-url="D:/桌面/bat/IP-223.bat" onClick="setIP(this);"/></div>
<div><input type="button" value="192.168.95.95" data-url="D:/桌面/bat/IP-223.bat" onClick="setIP(this);"/></div>
</div>
<div class="right_on div_style">
<div><span>应用程序</span></div>
<div><input type="button" value="计算器" onClick="runcalc();"/></div>
<div><input type="button" value="PLSQL Developer" data-url="D:/桌面/bat/PLSQL.bat" onClick="openFolder(this);"/></div>
<div><input type="button" value="WAMPSERVER" data-url="D:/桌面/bat/WAMPSERVER.bat" onClick="openFolder(this);"/></div>
</div>
</div>
<div style="display:inline-flex">
<div class="letf_un div_style">
<div><span>项目目录</span></div>
<div><input type="button" value="PHP项目工程目录" data-url="D:/桌面/bat/php-workspace.bat" onClick="openFolder(this);"/></div>
</div>
<div class="right_un div_style">
<div><span>区域四</span></div>
<div><input type="button" value="特殊应用" onClick="alert('等待添加中....');"/></div>
</div>
</div>
</div>
</body>
</html>