Combine scripts with Batch Processing

Source: Internet
Author: User

Batch processing is a good helper for us to manage computers and do some daily work. With the upgrade of Windows, batch processing can do more and more things. However, there are still many things that we cannot do with batch processing. Fortunately, Microsoft later added windows Script Host to Windows. Now we can use JScript or VBScript to do more complex work. In combination with WMI, it can be said that it is omnipotent. Wshscript is executed using cscript.exeor wscript.exe. cscript.exeand wscript.exe have some parameters. Setting different parameters may affect the running result. I have discovered that some scripts use the default interpreter (WScript.exe) and default parameters cannot get the expected results. In this case, when I write a script for other users, it is quite difficult to explain which parameters should I use cscript.exe or WScript.exe to run. How can this problem be solved? There is one way: Write another batch file and run this script in an appropriate way. However, I need two files. Can I use only one file? Yes! Combine scripts and batch processing !, Not only can the above problems be solved, but also the advantages of batch processing and WSH can be used at the same time.
The idea is to put the batch processing statement in the script comment. JScript can use/**/to annotate a piece of text, so I chose JScript. But/**/is an invalid character in batch processing. How can I introduce it without any unnecessary error prompts?

We need a statement that is accepted by both the batch processing and JScript and is useless to introduce. In JScript, there are such statements: @ set @ varname = value, while in batch processing: set varname = value. In batch processing, you can add @ before the statement to indicate that the sentence is not output. This is what we need! As for */, use @ rem.
See the following code (the extension is bat.Copy codeThe Code is as follows: @ set @ this_call_started = 1 /*
@ Echo off
@ Rem allows CMD. EXE Extension
@ SETLOCAL ENABLEEXTENSIONS
@ Rem allow CMD. EXE to delay expansion of Environment Variables
@ SETLOCAL ENABLEDELAYEDEXPANSION
...
The batch processing statement is written here.
...
@ Rem "% ~ Dpnx0 "extends the name of the batch processing file to a file with a complete path.
@ Rem % * all parameters of the batch processing file
@ Rem call this file again as a script file
@ Call CScript. EXE "% ~ Dpnx0 "// Nologo // e: jscript % *
...
The batch processing statement is written here.
...
@ Goto end_this_call
@ Rem */
// Windows Script Start ========================================== ====================
...
The script statement is written here.
...
// Windows Script end ========================================== ============================
/*
: End_this_call
...
The batch processing statement is written here.
...
@ Set @ this_call_started =
@ Rem */

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.