vbscript and batch hybridization

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

vbscript and batch hybridization

Post by MigrationUser »

09 May 2013 14:07
npocmaka

Code: Select all

'>nul 2>&1|| copy /Y %windir%\System32\doskey.exe %windir%\System32\'.exe >nul
'&&@echo off && cls &&goto :end_vbs 


WScript.Echo "Remorse is the echo of a lost virtue."
WScript.Quit

:end_vbs
'& cscript /nologo /E:vbscript %~f0
'& echo "Translation is at best an echo."
'& pause
'& rem del /q %windir%\System32\'.exe
close to the jeb's idea here

I've just wanted more neat looking script. The lines that start with : will be parsed by the script engine but will fail at execution so there's no need of :'
With worse performance ,but looks better :) . Eventually will require administrator permissions at first run. But still the script will have more one-liners than a 80's action movie :(

The idea is:
1. you are allowed to create a file named '.exe (which called from .bat will return the flow to the bat).
2.Doskey returns errorlevel 0 when is executed.And will do nothing when is called from bat.
3.'>nul 2>&1|| copy /Y %windir%\System32\doskey.exe %windir%\System32\'.exe >nul will create '.exe in system32
4.'& will be ignored by the vbscript and you can put there oneliners for the .bat

Last edited by npocmaka (19 Jul 2013 08:25)

----------------------------

#2 19 Jul 2013 20:35
npocmaka


Still thinking how this can be improved:

Code: Select all

:sub echo(str) :end sub
echo off
'>nul 2>&1|| copy /Y %windir%\System32\doskey.exe %windir%\System32\'.exe >nul

'& echo/ 
'& cscript /nologo /E:vbscript %~f0
'& echo/
'& echo BATCH: Translation is at best an ECHO.
'& echo/
'& pause
'& del /q "%windir%\System32\'.exe" & exit /b

WScript.Echo "VBScript: Remorse is the ECHO of a lost virtue."
WScript.Quit
This will not clear the screen and will not show error messages , but still will print one redundant echo off

Last edited by npocmaka (20 Jul 2013 17:46)

----------------------------

#3 20 Jul 2013 14:25
jeb

Hi npocmaka,

I also tried many (really many) things, but can't find a solution.

The main problem for me is, that only two things are not displayed by the batch parser.
Lines beginning with a @ and lines beginning with a :label.
Also yu are allowed to prefix both with ;,= and spaces, also redirection before a label is allowed and wouldn't be displayed.

But I suppose that labels are useless here, as they don't solve the problem to inject an @echo off, you simply move the problem to the next line.
Also the | and & are useless, as they will be printed without echo off.

Annoyingly, redirects are not allowed in front of an at sign, then it doesn't work anymore.
Else the problem could be solved easily.

Code: Select all

<nul :lab next line invisble for batch^
a=1_
<2' <nul echo off
But as @ seems to be an invalid character for vbs everywhere except strings, it's hard to see a solution.
I could also see a solution if the percent can be used in vbs, but it seems also an invalid character without function.

Perhaps this helps, or you know where @ or % is valid in vbs

----------------------------

#4 20 Jul 2013 18:20
npocmaka


@ and % cant be used in VBS outside a string.May be if the are used in WSF file... but seems impossible to create a clear WSF/bat hybrid ??

At the moment seems that this creates the less noise with less lines:

Code: Select all

:sub echo(str) :end sub
echo off
I thought of sending backspase or del trough the vbscript with intention to delete the the echo ff but does not work :-D

Last edited by npocmaka (20 Jul 2013 18:24)

----------------------------

#5 09 Oct 2013 21:15
npocmaka


One more way - when .WSF is used the cscript/wscript does not care much about the things outside the xml-described jobs as long as they don't contain xml special characters:

Code: Select all

@echo off
goto :skip_xml_comment
<!--
:skip_xml_comment

echo(
echo Echo from the batch
echo(

( ren %0 %0.wsf 
 cscript %0.wsf 
 ren %0.wsf %0  )
 
 
exit /b 0
-->

<package>
   <job id="vbs">
      <script language="VBScript">

         WScript.Echo "Echo from the VBS"
 
      </script>
   </job>
</package>
This one includes self renaming of the batch itself (still faster than a temp file) which is more or less risky.
But annoying displaying of "@echo off" is gone and batch code is without one-line restrictions.And using .WSF adds some flexibility.
.As the XML parsers do not like the & ; > < symbols the batch stuff should be put in xml comment for safety (or cdata section which will be uglier).
Renaming , calling of cscript and and returning old name of the batch should be done in one line (or in brackets).

Still I have no perfect solution (may be this is the best one?) ...

I will update my answer in the Dave's question in SO too :)

Last edited by npocmaka (10 Oct 2013 05:53)
Post Reply