Home  >  Article  >  Web Front-end  >  Js uses WScript.Shell object to execute .bat files and cmd commands_javascript skills

Js uses WScript.Shell object to execute .bat files and cmd commands_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:25:442419browse

WScript.Shell (Windows Script Host Runtime Library) is an object, and the corresponding file is C:/WINDOWS/system32/wshom.ocx. Wscript.shell is a component used by the server system. Shell means "shell". This object can perform common operations of the operating system shell, such as running programs, reading and writing the registry, environment variables, etc. This object is usually used in VB or VBS programming.

Install WScript.Shell object: regsvr32 WShom.Ocx

Uninstall WScript.Shell object: regsvr32 -u WShom.Ocx or regsvr32 /u WShom.Ocx

 For Example:

1. Create the test.bat file and save it in the D: root directory. The function is to copy the *txt file to the d:/test directory. ​

Copy code The code is as follows:

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

2. Create a WScript.Shell object and run the test.dat file directly from this object.

Copy code The code is as follows:

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

3. Create a WScript.Shell object and run the CMD command directly from this object.

Copy code The code is as follows:

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)

The method is very simple but very practical. I recommend it to my friends

Statement:
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 admin@php.cn