Home > Web Front-end > JS Tutorial > body text

Js使用WScript.Shell对象执行.bat文件和cmd命令_javascript技巧

WBOY
Release: 2016-05-16 16:25:44
Original
2269 people have browsed it

WScript.Shell(Windows Script Host Runtime Library)是一个对象,对应的文件是C:/WINDOWS/system32/wshom.ocx,Wscript.shell是服务器系统会用到的一种组件。shell 就是“壳”的意思,这个对象可以执行操作系统外壳常用的操作,比如运行程序、读写注册表、环境变量等。这个对象通常被用在VB或VBS编程中。

  安装WScript.Shell对象:regsvr32 WShom.Ocx

  卸载WScript.Shell对象:regsvr32 -u WShom.Ocx 或者 regsvr32 /u WShom.Ocx

  For Example:

  1. 建立test.bat文件,存于D:根目录下,作用是将*txt文件拷贝到d:/test目录下。  

复制代码 代码如下:

md test
copy d:/*.txt d:/test
pause

   2. 创建WScript.Shell对象,由该对象直接运行test.dat文件。

复制代码 代码如下:

var objShell;
objShell=new ActiveXObject("WScript.Shell");
var iReturnCode=objShell.Run("c:/test.bat",0,true);

   3. 创建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)

方法很简单,却很实用,这里推荐给小伙伴们

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!