Is it possible to embed and execute VBScript within a batch file without using a temporary file?

后端 未结 6 911
慢半拍i
慢半拍i 2020-11-22 04:39

People have been embedding and executing VBScript within batch files for a long time. But all the published solutions that I have seen (at the time this question was ori

6条回答
  •  不思量自难忘°
    2020-11-22 05:34

    EDIT: My first answer was wrong for VBScript, now my next try...

    Nice idea to use CTRL-Z, but I don't like control characters in a batch file, as it is problematic to copy&paste them.
    It's depends of your browser, of your editor, of your ...

    You could get a hybrid VBScript/Batch also with normal characters, and "normal" code.

    :'VBS/Batch Hybrid
    :
    :
    :'Makes the next line only visible for VBScript ^
    a=1_
    <1' echo off 

    The trick is to prepend each batch line with set n=n'& it is legal for both, but vbs will ignore the rest of the line, only batch will execute the rest of the line.

    The other variant is :'remark ^, this is a remark for both, but for batch this remarks also the next line by the multiline character.
    The VbScript sees then a=1<1 the rest of the line is a remark '
    The batch sees only <1' echo off , the first redirect from 1' will be override by the second , so it results to only echo off < nul.

    The only remaining problem is that you can see the first echo off, as it doesn't work in batch to use the @ after a redirection.

    For JScript exists a simpler solution hybrid scripting

提交回复
热议问题