Scripts are combined with batches _ other

Source: Internet
Author: User
Batch processing is a good helper for us to manage computers and do some daily work, and with the upgrade of Windows, batch processing can do more and more things. But there are still a lot of things we can't do with batch processing. Fortunately, Microsoft added Windows Script Host to Windows and we can now do more complex work with JScript or VBScript, with WMI, which can be said to be omnipotent. WSH scripts are executed with CScript.exe or WScript.exe, CScript.exe and WScript.exe have some parameters, and setting different parameters may affect the results of the operation. I have found that scripts that use the default interpreter (WScript.exe) and default parameters do not get the results I want. So when I write a script for someone else to use, it's going to take a lot of breath to explain what parameters to run with CScript.exe or WScript.exe. How to solve this problem? There is one way to do this: write a different batch file and run the script in the appropriate way. But then I need two files. Can you just use one file? Combine script and batch processing together!, not only can solve these problems, but also can take advantage of batch processing and WSH respective advantages.
The idea is to put batch statements in the comments in the script. JScript can annotate a text with/*//, so I chose JScript. But * * */In the batch is illegal characters, how can it be introduced without any unwanted error prompts?

We need a batch and a statement that is not used by JScript to introduce * *. There are such statements @set @varname =value in JScript, but also in batches: Set Varname=value, which can be preceded by a @ in a batch to indicate that the sentence is not output. This is what we need! As for the * * is very good, with @rem * * can.
Take a look at the following code (with the extension bat), which is simple.
Copy Code code as follows:

@set @this_call_started =1/*
@echo off
@rem allow CMD.EXE extended functionality The
@SETLOCAL enableextensions
@rem allows CMD.EXE to delay the expansion of environment variables
@SETLOCAL enabledelayedexpansion
...
> The batch statement is written here
... The
@rem "%~dpnx0" extends the file name of the batch file itself to a file name with the full path
@rem%* all parameters of the batch file itself
@rem re-invoke this file as a script file
@call Cscrip T.EXE "%~dpnx0"//nologo//e:jscript%*
...
The batch statement is written here
...
@goto end_this_call
@rem */
//windows Script start==================================================
...
Script statements are written here
...  
//windows Script end=====================================================
/*
: End_this_call
...
The batch 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.