Page 4 of 5
Re: js/vbs/html/hta hybrids and chimeras in cmd/bat
Posted: 15 Jun 2015 05:58
by npocmaka_
you need to call the job by its ID:
Code: Select all
@cScript.EXE //noLogo "%~f0?.WSF" //job:javaScript /arg0:sleep_ /arg1:time
@cScript.EXE //noLogo "%~f0?.WSF" //job:VBScript /arg0:sleep_ /arg1:time
@exit /b 0
<package>
<job id="javaScript">
<script language="JScript">
WScript.Echo( "hi" );
WScript.Echo(WScript.Arguments.Item(1));
</script>
</job>
<job id="VBScript">
<script language="VBScript">
WScript.Echo("blah"):
</script>
</job>
</package>
and you need to put your jobs in a package.
Re: js/vbs/html/hta hybrids and chimeras in cmd/bat
Posted: 15 Jun 2015 06:16
by Ed Dyreen
My god what is wrong with me today, I even misspelled job ID.
thank u very much npocmaka_, it works now
Re: js/vbs/html/hta hybrids and chimeras in cmd/bat
Posted: 25 Jun 2015 05:24
by npocmaka_
mshta without splash :
Code: Select all
@echo off
mshta.exe "%~f0"|more
exit /b
<HTA:Application
ShowInTaskbar = no
WindowsState=Minimize
SysMenu=No
ShowInTaskbar=No
Caption=No
Border=Thin
>
<script language="javascript" type="text/javascript">
window.visible=false;
window.resizeTo(1,1);
var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
fso.WriteLine("waiting 5 seconds");
function waitSeconds(iMilliSeconds) {
var counter= 0
, start = new Date().getTime()
, end = 0;
while (counter < iMilliSeconds) {
end = new Date().getTime();
counter = end - start;
}
}
waitSeconds(5000);
var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
close(fso.Write("test hta window visibility"));
</script>
the mshta splash is not visible , but for moment the focus is lost from the cmd console.
At the beginning it sets some hta tags to reduce interaction elements (though the hta part can be removed - it is not the important part - without it for a moment a small window will be visible while application is closed) :
Code: Select all
https://technet.microsoft.com/en-us/library/ee176567.aspx
then applies on the window object (the mother and the father of everything in javascript when the context is a browser) resize and visibility to false.
as the HTA is some kind of internet explorer you can use methods/properties from IWebBrowser2 :
Code: Select all
https://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx
Re: js/vbs/html/hta hybrids and chimeras in cmd/bat
Posted: 01 Jul 2015 02:47
by npocmaka_
One more reason to love mshta.With hta application you can use ecmascript 6 features (while wsh jscript is ecmascript 4 compatible ):
Code: Select all
@echo off
mshta.exe "%~f0"|more
exit /b
<HTA:Application
ShowInTaskbar = no
WindowsState=Minimize
SysMenu=No
ShowInTaskbar=No
Caption=No
Border=Thin
>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<script language="javascript" type="text/javascript">
window.visible=false;
window.resizeTo(1,1);
var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';
var obj = JSON.parse(text);
var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
fso.Write(obj.name + "\r\n" + obj.street + "\r\n" + obj.phone);
close();
</script>
You need installed IE11 and
<meta http-equiv="x-ua-compatible" content="ie=edge" /> . Probably will be not so useful for old XP/2003 machines , but is good to know as allows usage of callback functions , promises , JSON and so on. Including some cool javascript libraries that cannot be used with wsh/jscript.
Re: js/vbs/html/hta hybrids and chimeras in cmd/bat
Posted: 21 Dec 2015 05:52
by siberia-man
The script was updated:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5543&p=37780#p37780Some cosmetic changes and support for Python were done.
Re: js/vbs/html/hta hybrids and chimeras in cmd/bat
Posted: 21 Jul 2016 09:27
by siberia-man
The script was updated:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5543&p=37780#p37780.
After this thread
We can use bash in our scripts now in Win10 I decided to add (the variant with heredoc) the support of hybrid of Bash in Cmd.
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 21 Jul 2016 12:15
by npocmaka_
Anyway the thread was resurrected...
Here's one more highly imperfect way to make a hybrid with vbscript that just came to me:
Code: Select all
:sub c() :end sub:
C: '& @echo off
C: '& echo batch
C: '& cscript /nologo /E:vbscript %~f0
C: '& exit /b 0
WScript.Echo "VBScript"
WScript.Quit
it just uses jump to drives in the batch part and for the drive letter there's a prepared subroutine in the vbscript part.
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 16 Sep 2016 13:27
by npocmaka_
turns out rundll32 also can execute jsvascript/vbscript code (though it is calling the mshtml.dll):
rundll32.exe javascript:"\..\mshtml.dll,RunHTMLApplication ";eval("w=new%20ActiveXObject(\"WScript.Shell\");w.Exec(\"calc\")");
https://gist.github.com/subTee/62fc28bb ... 6d65921bd2
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 07 Feb 2017 07:41
by npocmaka_
Rather an
important note for the wsh scripts.
To be able to pass non named arguments to the script that starts with '//' you'll need to put '//' after the script name:
Code: Select all
@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" // %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
WScript.Echo(WScript.Arguments.Item(0));
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 05 Apr 2018 15:40
by Marblo
Maybe you could even add ps support to this script. I don't know how to invoke the batch as a .ps script but the output could look like this :
Code: Select all
<# :: batch part
Echo hello world
Exit
#>
(some ps commands)
Sorry for typos or bad english :rol:
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 05 Apr 2018 19:52
by Squashman
Marblo wrote: ↑05 Apr 2018 15:40
Maybe you could even add ps support to this script. I don't know how to invoke the batch as a .ps script but the output could look like this :
Read the whole thread.
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 06 Apr 2018 06:11
by ShadowThief
Marblo wrote: ↑05 Apr 2018 15:40
Maybe you could even add ps support to this script. I don't know how to invoke the batch as a .ps script but the output could look like this :
Code: Select all
<# :: batch part
Echo hello world
Exit
#>
(some ps commands)
Sorry for typos or bad english :rol:
PowerShell support already exists for this script. It's the one time I've ever used it.
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 01 May 2018 11:49
by jfl
I think the PowerShell support can be simplified, based on a post at
https://stackoverflow.com/a/49063524
Here's an improved version of their script:
Code: Select all
<# :# PowerShell comment protecting the Batch section
@echo off
setlocal EnableExtensions DisableDelayedExpansion
:# Prepare batch arguments
set ARGS=%*
if defined ARGS set ARGS=%ARGS:"=\"%
if defined ARGS set ARGS=%ARGS:'=''%
echo In Batch
PowerShell -c ^"Invoke-Expression ('^& { ' + [io.file]::ReadAllText(\"%~f0\") + '} %ARGS%')"
echo Back in Batch. PowerShell exit code = %ERRORLEVEL%
exit /b
###############################################################################
# End of the PS comment around the Batch section; Begin the PowerShell section #>
echo "In PowerShell"
$Args | % { "PowerShell Args[{0}] = '$_'" -f $i++ }
exit 0
The important trick I added is to ^escape the first double quote in the PowerShell command.
This ensures that the ^ & | < > special characters in quoted batch arguments are still protected by their quotes in the PowerShell command line, and make it through safely.
Cherry on the cake, you can even pass double quotes by doubling them:
Code: Select all
C:\JFL\SRC\Batch>"bat+ps1.bat" one 2 "three four $#^!&|<>'"""
In Batch
In PowerShell
PowerShell Args[0] = 'one'
PowerShell Args[1] = '2'
PowerShell Args[2] = 'three four $#^!&|<>'"'
Back in Batch. PowerShell exit code = 0
C:\JFL\SRC\Batch>
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 05 May 2018 04:12
by siberia-man
Re: js/vbs/html/hta and more hybrids and chimeras in cmd/bat
Posted: 06 Nov 2019 16:14
by DQ2000