DosTips.com

A Forum all about DOS Batch
It is currently 20 Aug 2017 22:46

All times are UTC-06:00




Post new topic  Reply to topic  [ 54 posts ]  Go to page Previous 1 2 3 4
Author Message
PostPosted: 15 Jun 2015 05:58 
Offline

Joined: 24 Jun 2013 17:10
Posts: 437
Location: Bulgaria
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.


Top
   
PostPosted: 15 Jun 2015 06:16 
Offline
Expert

Joined: 16 May 2011 08:21
Posts: 1436
Location: Flanders(Belgium)
My god what is wrong with me today, I even misspelled job ID. :roll:

thank u very much npocmaka_, it works now :D


Top
   
PostPosted: 25 Jun 2015 05:24 
Offline

Joined: 24 Jun 2013 17:10
Posts: 437
Location: Bulgaria
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


Top
   
PostPosted: 01 Jul 2015 02:47 
Offline

Joined: 24 Jun 2013 17:10
Posts: 437
Location: Bulgaria
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.


Top
   
PostPosted: 21 Dec 2015 05:52 
Offline

Joined: 26 Dec 2013 09:28
Posts: 90
The script was updated: http://www.dostips.com/forum/viewtopic.php?f=3&t=5543&p=37780#p37780

Some cosmetic changes and support for Python were done.


Top
   
PostPosted: 21 Jul 2016 09:27 
Offline

Joined: 26 Dec 2013 09:28
Posts: 90
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.


Top
   
PostPosted: 21 Jul 2016 12:15 
Offline

Joined: 24 Jun 2013 17:10
Posts: 437
Location: Bulgaria
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.


Top
   
PostPosted: 16 Sep 2016 13:27 
Offline

Joined: 24 Jun 2013 17:10
Posts: 437
Location: Bulgaria
turns out rundll32 also can execute jsvascript/vbscript code (though it is calling the mshtml.dll):

Quote:
rundll32.exe javascript:"\..\mshtml.dll,RunHTMLApplication ";eval("w=new%20ActiveXObject(\"WScript.Shell\");w.Exec(\"calc\")");


https://gist.github.com/subTee/62fc28bb ... 6d65921bd2


Top
   
PostPosted: 07 Feb 2017 07:41 
Offline

Joined: 24 Jun 2013 17:10
Posts: 437
Location: Bulgaria
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));


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 54 posts ]  Go to page Previous 1 2 3 4

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited