-1

I'd like to execute vbscript code from java

I understand that the following code executes a vbs file.

Runtime.getRuntime().exec("wscript test.vbs");

But what I need is to execute the code inside vbs file itself from java instead of having the vbs file saved in the system. In my environment I am not allowed to save vbs files in system.

I am looking for something like

Runtime.getRuntime().exec("wscript 'vbscript code itself'");
alroc
  • 27,574
  • 6
  • 51
  • 97
Ramsey
  • 1
  • 1
  • possible duplicate of [There's any way to run vbscript directly to wscript or cscript command line](http://stackoverflow.com/questions/13115508/theres-any-way-to-run-vbscript-directly-to-wscript-or-cscript-command-line) – Jacob Krall Dec 04 '13 at 19:31
  • @JacobKrall , In my case I am not allowed to use a batch or vbs file in the system. I am looking for a solution to execute the actual vbscript code itself. – Ramsey Dec 04 '13 at 19:34

2 Answers2

3

You can't. The VBScript hosts (wscript, cscript, ie, mshta) all work with input files. There is a (dated) script control that eats code, but to use that from Java, you'll have to do COM.

In your shoes I'd forget VBScript and research "scripting Java" random link.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
0

This runs from the command line,

mshta vbscript:Execute("Dim sapi:Set sapi=CreateObject(""sapi.spvoice""):sapi.Speak ""THIS IS A TEST OF THE EMERGENCY BROADCAST SYSTEM."":set sapi=nothing ")
Aimee Borda
  • 842
  • 2
  • 11
  • 22