JS using the Wscript.Shell object to execute the. bat file and the cmd command

Source: Internet
Author: User

JS using the Wscript.Shell object to execute the. bat file and the cmd command

Http://www.jb51.net/article/58669.htm

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 do the operating system shell commonly used operations, such as running programs, read and write registry, environment variables and so on. This object is usually used in VB or VBS programming.

Install Wscript.Shell object: regsvr32 wshom.ocx

Unload Wscript.Shell object: Regsvr32-u wshom.ocx or regsvr32/u wshom.ocx

For Example:

1. Create the Test.bat file, stored in the D: root directory, the role is to copy the *txt file to the D:/test directory.

Copy CodeThe 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 from the object.

Copy CodeThe code is as follows: Var Objshell; Objshell=new ActiveXObject ("Wscript.Shell"); var ireturncode=objshell.run ("C:/test.bat", 0,true);

3. Create the Wscript.Shell object, run the cmd command directly from the object.

Copy CodeThe 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, this is recommended for small partners

JS using the Wscript.Shell object to execute the. bat file and the cmd command

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.