Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>And my attempt (<a href="http://ss64.org/viewtopic.php?id=1700" rel="nofollow">first posted here</a>).It resembles the jeb's solution ,but (at least according to me) the code is more readable:</p> <pre><code>:sub echo(str) :end sub echo off '&gt;nul 2&gt;&amp;1|| copy /Y %windir%\System32\doskey.exe %windir%\System32\'.exe &gt;nul '&amp; echo/ '&amp; cscript /nologo /E:vbscript %~f0 '&amp; echo/ '&amp; echo BATCH: Translation is at best an ECHO. '&amp; echo/ '&amp; pause '&amp; rem del /q "%windir%\System32\'.exe" '&amp; exit /b WScript.Echo "VBScript: Remorse is the ECHO of a lost virtue." WScript.Quit </code></pre> <p>And the explanation:</p> <ol> <li><em><strong>'</em></strong> (single quote) is not forbidden symbol as a part of a file name in windows so there is no problem to have a file called <code>'.exe</code></li> <li>There are few commands packed with windows that do nothing without command line parameters.The fastest (at doing nothing) and most light as a size (according to my tests) are <code>subst.exe</code> and <code>doskey.exe</code></li> <li>So at the first line I'm coping the <code>doskey.exe</code> to <code>'.exe</code> (if it does not already exist) and then continue using it as <code>'&amp;</code> (as the .exe extension should be in <strong>%PATHEXT%</strong>).This will be taken as a comment in VBScript and in batch will do nothing - just will continue with the next command on the line. </li> </ol> <p>There are some flaws of course .At least for the first run eventually you will need administrator permissions as the coping in <code>%windir%\System32\</code> might be denied.For robustness you can also use <code>'&gt;nul 2&gt;&amp;1|| copy /Y %windir%\System32\doskey.exe .\'.exe &gt;nul</code> and then at the end: <code>'&amp; rem del /q .\'.exe</code></p> <p>With <code>'.exe</code> left in your path you could unintentially to use it in improper way , and the execution on every line of '.exe eventually could decrease the performance.</p> <p>..And in the batch part commands must be only in one line.</p> <p><strong>Update 9.10.13 (..following the above convention)</strong></p> <p>Here's one more way which requires self-renaming of the batch file:</p> <pre><code>@echo off goto :skip_xml_comment &lt;!-- :skip_xml_comment echo( echo Echo from the batch echo( ( ren %0 %0.wsf cscript %0.wsf ren %0.wsf %0 ) exit /b 0 --&gt; &lt;package&gt; &lt;job id="vbs"&gt; &lt;script language="VBScript"&gt; WScript.Echo "Echo from the VBS" &lt;/script&gt; &lt;/job&gt; &lt;/package&gt; </code></pre> <p>And a short explanation:</p> <ol> <li>When the batch is self-renamed and renamed again with the old name , and this is done in one line (or in brackets) the script will be executed with no errors.In this case is added also one call of <code>CSCRIPT.EXE</code> with <a href="http://en.wikipedia.org/wiki/Windows_Script_File" rel="nofollow"><code>.WSF</code></a> file.Self-renaming is a little bit risky , but faster than a temp file.</li> <li>Windows script host does not care much for items outside of xml data as long as there are no special xml symbols <code>&amp; &lt; &gt; ;</code> so <code>@echo off</code> and <code>goto</code> can be used without worries. But for safety it's good to put batch commands in xml comment (or CDATA ) section .To avoid error messages from the batch I've skipped the <code>&lt;!--</code> with <code>goto</code> here.</li> <li>Before closing the xml comment batch script is terminated with <code>exit</code></li> </ol> <p>So the good things are that there's no need to write all batch code in single line commands, there's no annoying <code>echo off</code> displayed , jscript code and different jobs could be added to the script.Also no need of special symbols and creation of additional exe files like <code>'.exe</code></p> <p>On the other hand self-renaming could be risky.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload