On Thursday, December 6, 2012 8:23:23 PM UTC-5, Auric__ wrote:
> Tom Lavedas wrote:
>
> Ok, it works. Looks a bit like line noise, though.
Yes, and when I looked at it again, I am confused as to why it worked at all. Upon further consideration I suspect (but have not proven) it is causing a runtime error which causes the HTA window to close because the process aborts - but not until after it has output the expected result.
Regardless of whether this is the correct interpretation, I have altered the construct, which makes it a tiny bit less like 'line noise' ...
Command prompt entry to create macro:
doskey vb=for /f "delims=" %a in ('mshta vbscript:Execute("createobject("""scripting.filesystemobject""").GetStandardStream(1).write($*):close"^^^)') do @echo %a
The macro file version for DOSKEY:
vb=for /f "delims=" %a in ('mshta vbscript:Execute("createobject(""scripting.filesystemobject"").GetStandardStream(1).write($*):close"^)') do @echo %a
And finally the batch file version:
:: VBS.cmd, Tom Lavedas 12/07/2012
@echo off & setlocal
set VBS=vbscript:Execute("createobject(""scripting.filesystemobject"")
set VBS=%VBS%.GetStandardStream(1).write
for /f "delims=" %%a in ('mshta %VBS%(%*):close"^)') do echo.%%a
:: Examples
::
:: Display ASCII equivalents (in hex) for first 127 characters ...
:: @for /l %N in (1,1,127) do @vbs right(""00""+hex(""%N"")+"":"",4)+chr(%N)
::
:: @for /f %Y in ('vbs date-1') do set Yesterday=%Y
::
:: @for /f %P in ('vbs 4*atn(1^)') do set PI = %P
::
:: This form just displays the results
:: vbs SQR(2^)
Finally, regarding the applicability of this approach: I suspect the command line support for the "vbscript:" construct is version dependent. I seem to remember people lamenting the fact that it was possible to use "javascript:" on the command line, but not vbscript.
So, as more universal version could construct JScript code, but I haven't done that yet. The alternative is to use an "about:<script type=text/vbs> ... </script> construct, which I have done in the past. In fact, I jsut played with a login GUI application that returns its results to the calling batch procedure ...
:: PWGUI.cmd, Tom Lavedas 12/06/2012
@echo off & setlocal
set "scr=<hta:application sysmenu=no contextmenu=no />"
set "scr=%scr%<title>Login</title>"
set "scr=%scr%<script type=text/vbs>"
set "scr=%scr%resizeTo 300,150:"
set "scr=%scr%sub ok_onclick:"
set "scr=%scr%createobject("scripting.filesystemobject")."
set "scr=%scr%GetStandardStream(1).write UID.value&chr(32)&PW.value:"
set "scr=%scr%close:end sub"
set "scr=%scr%</script>"
set "scr=%scr%<body scroll=no bgcolor=#dfdfdf onload=uid.focus>"
set "scr=%scr%<span style=width:75>UserID:</span>"
set "scr=%scr%<input type=text id=UID style=width:150></br>"
set "scr=%scr%<span style=width:75>Password:</span>"
set "scr=%scr%<input type=password id=pw style=width:150><hr>"
set "scr=%scr%<center><input type=submit id=OK value=OK>"
for /f "tokens=1,2" %%a in ('mshta "about:%scr%"') do echo UID:%%a, PW:%%b
One note, the command line length limitation restricts the size of script that can be used. I ran into that limitation with earlier versions of the script above in Win7, when I tried to add some bells and whistles. That is one of the reasons some of the HTML tags that would normally be used are left off. The host supplies these as it interprets the supplied code. So, to reduce character count, I removed them.
_____________________________
Tom Lavedas