/* * @(#)Scrit.java 1.0 2002/08/11 * * Copyright (c) 2002 Michel I. Gallant * @author Michel I. Gallant */ import com.ms.activeX.*; import com.ms.com.*; import java.io.*; import com.ms.dll.*; import com.ms.io.Path; class Scrit { public static void main(String args[]) { int endcmd = -1; int pCmdLn = GetCommandLine() ; //returns LPTSTR, so treat as raw pointer String strCmdLn = DllLib.ptrToString(pCmdLn).trim(); //remove leading and trailing whitespace if (strCmdLn.charAt(0)=='\"' && strCmdLn.endsWith("\"") ) //if entire line surrounded by quotes, strCmdLn = Path.removeBeginEndQuotes(strCmdLn); //remove them String lcstrCmdLn = strCmdLn.toLowerCase() ; String cmdargs=""; if (lcstrCmdLn.indexOf("scrit.exe")>=0){ endcmd = lcstrCmdLn.indexOf("scrit.exe") + 9; cmdargs = strCmdLn.length()>endcmd ? strCmdLn.substring(endcmd).trim() : "" ; } else if(lcstrCmdLn.indexOf("scrit")>=0){ endcmd = lcstrCmdLn.indexOf("scrit") + 5; //System.out.println("Length: " + strCmdLn.length() + " endcmd: " + endcmd) ; cmdargs = strCmdLn.length()>endcmd ? strCmdLn.substring(endcmd).trim() : "" ; } else System.exit(1); cmdargs =Path.removeBeginEndQuotes(cmdargs) ; //-- replace any \" escaped quotes with quotes -- int index=0; while ((index = cmdargs.indexOf("\\\"")) >= 0) cmdargs = cmdargs.substring(0, index) + "\"" + cmdargs.substring(index+2,cmdargs.length()); //----------------------------------------------- ActiveXComponent oScrCtrl = new ActiveXComponent("MSScriptControl.ScriptControl") ; Variant [] stringargs = { new Variant(cmdargs) }; oScrCtrl.setProperty("Language",new Variant("Vbscript")) ; oScrCtrl.setProperty("AllowUI",new Variant(true)) ; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); try{ if(!cmdargs.equals("")){ //if command-line string has code try{ oScrCtrl.invoke("AddCode", stringargs); } catch(ComFailException ce){System.out.println("Invalid script");} } System.out.println("Enter vbscript to execute, or to exit:\n" ) ; while( !(cmdargs = in.readLine()).equals("")){ stringargs[0] = new Variant(cmdargs); try{ oScrCtrl.invoke("AddCode", stringargs); } catch(ComFailException ce){System.out.println("Invalid script");} } } catch(IOException ioe) {System.out.println("Problem reading stdin");} } /** @dll.import("KERNEL32",auto) */ private native static int GetCommandLine (); }