Javascript uses the WScript. Shell object to execute the. bat file and cmd command _ javascript skills

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.