Home  >  Article  >  Web Front-end  >  What is the usage of WScript in javascript

What is the usage of WScript in javascript

藏色散人
藏色散人Original
2023-02-10 09:36:152283browse

The method of using WScript in JavaScript is: 1. Create the "test.bat" file and save it in the "D:" root directory; 2. Create the "WScript.Shell" object and run it directly "test.dat" file; 3. Run the CMD command directly from the "WScript.Shell" object.

What is the usage of WScript in javascript

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

What is the usage of WScript in javascript?

Use the WScript.Shell object in Javascript to execute .bat files and cmd commands

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 store it in the D: root directory. The function is to copy the *txt file to the d:/test directory.​

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

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

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 the object.

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)

Recommended study: "JavaScript Video Tutorial"

The above is the detailed content of What is the usage of WScript in javascript. For more information, please follow other related articles on the PHP Chinese website!

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