This article mainly introduces how to use WScript in Js. shell object execution. bat file and cmd command. For more information, see WScript. shell (Windows Script Host Runtime Library) is an object corresponding to C:/WINDOWS/system32/wshom. ocx, Wscript. shell is a component used by the server system. Shell is the meaning of "shell". this object can perform common operations on the operating system shell, such as running programs, reading and writing registries, and environment variables. 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.
The code is as follows:
Md test
Copy d:/*. txt d:/test
Pause
2. create a WScript. Shell object that runs the test. dat file directly.
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.
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 simple but practical. we recommend it to our friends here