JS uses the Wscript.Shell object to execute. bat files and cmd commands _javascript tips

Source: Internet
Author: User

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 that the server system will use. Shell is the meaning of "shell", this object can perform operating system shell commonly used operations, such as running the program, read and write the registry, environment variables. This object is commonly 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 test.bat files, stored in the D: root directory, the role is to copy *txt files to the D:/test directory.

Copy Code code as follows:

MD Test
Copy D:/*.txt D:/test
Pause

2. Create a Wscript.Shell object that runs the Test.dat file directly from the object.

Copy Code code as follows:

var Objshell;
Objshell=new ActiveXObject ("Wscript.Shell");
var ireturncode=objshell.run ("C:/test.bat", 0,true);

3. Create a Wscript.Shell object that runs the cmd command directly from the object.

Copy Code code 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, here recommended to the small partners

Related Article

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.