Welcome, guest | Sign In | My Account | Store | Cart

Have you a wish to launch VBScript without temporary files and right from batch? Maybe you think that it's not possible, but you think wrong. Do you remember my post for executing JScript from batch? So, maybe you are familiar with 'MSScriptControl' object which helps to execute JScript code in VBScripts or conversely - VBScript code inside JScripts. Let's take a look.

Batch, 30 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@set @env=0 /*
  @echo off
    set @env=
    cscript //nologo //e:jscript "%~dpnx0"
  exit /b
'intBig = 100
'intLow = 1
'
'For i = 1 To 5
'  Randomize
'  intRes = Int((intBig - intLow + 1) * Rnd + intLow)
'  WScript.Echo intRes
'Next
*/

with (new ActiveXObject('Scripting.FileSystemObject')) {
  with (new ActiveXObject('MSScriptControl.ScriptControl')) {
    var f, s, code = "";
    f = OpenTextFile(WScript.ScriptFullName, 1);
    while (!f.AtEndOfStream) {
      s = f.ReadLine();
      if (s.match(/^\'(\w+|\s+|\=*.)+$/g)) code += s;
    }
    f.Close();
    
    language = 'VBScript';
    addobject('WScript', WScript, true);
    addcode(code.split(/'/).join('\n'));
  }
}
Created by greg zakharov on Thu, 15 Nov 2012 (MIT)
Batch recipes (42)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks