<?xml version="1.0" encoding="ISO-8859-1"?> <!-- File: JavaSysProps.wsf (WSF for VBscript) Author: (c) M. Gallant 10/04/2000 Demonstrates use of Java monikers to instantiate custom Java class objects. The compiled Java class bytecode file must be in the Win32 classpath. This typically includes: C:\windows\java\classes C:\windows\java\trustedclasses Note that Java objects can be used without formally registering them as COM objects using the JavaReg utility of the MS-SDK/Java. Note that to use Java classes with Java monikers, the class must have a default (no arguments) constructor. A simple wrapper Java class can provide ready access to any Java class without default constructors, of Java static methods. This provides extremely powerful functionality based on the Java API and Microsoft extensions. The simple example below enumerates all the Java System properties, and displays them in an InternetExplorer.Application window. The procedure "ShowIEWindow(title, text)" below is based on: Microft Windows Script Host 2.0 Developer's Guide Gunter Born Microsoft Press 2000 p. 453 Listing 14-14 References: http://msdn.microsoft.com/workshop/essentials/webmen/webmen080398.asp http://www.microsoft.com/Java/sdk/40/pg/pg_javacom_31.htm Compile the code below with your favorite Java compiler: java JavaSystemProps.java (Sun JDK compiler) jvc JavaSystemProps.java (Microsoft VJ++ compiler) ------------- Java Source Code ------------ import java.io.* ; import java.util.*; public class JavaSystemProps { String nl= System.getProperty("line.separator") ; StringBuffer strbuff = new StringBuffer() ; public String getParameters() { Properties sysprops = System.getProperties() ; Enumeration enprop = sysprops.propertyNames() ; while ( enprop.hasMoreElements() ) { String key = (String) enprop.nextElement() ; strbuff.append(key + "\t" + sysprops.getProperty(key) + nl) ; } return strbuff.toString() ; } } ------------- End Java Source ------------ --> <job id="J1"> <script language="VBScript"> <![CDATA[ Option Explicit Dim oJSysProps, oWshShell, properties set oWshShell = CreateObject("WScript.Shell") set oJSysProps = GetObject("java:JavaSystemProps") 'Instantiate Java object via moniker. properties = oJSysProps.getParameters() ShowIEWindow "Java System Properties", properties Sub ShowIEWindow(title, text) Dim oIE, oDoc text = "----------- Java System Properties ------------" & vbCrLf & text ' Create Internet Explorer Application object. Set oIE = WScript.CreateObject("InternetExplorer.Application") ' ---- Window Properties ------ oIE.left = 10 oIE.top = 10 oIE.height = 300 oIE.width = 600 oIE.menubar = 0 oIE.toolbar = 0 oIE.statusbar = 0 oIE.navigate("about:blank") ' Create an empty HTML document. oIE.visible = 1 ' Keep Internet Explorer visible. Do While(oIE.Busy) ' Wait for Window WScript.Sleep 200 Loop Set oDoc = oIE.Document ' Get Document object. oDoc.open ' Open document. ' Write script to the document object. oDoc.writeln("<html><head><title>" & title & "</title></head>") oDoc.writeln("<body bgcolor='#FFFFFF'><"XMP>" & text & "<" & "/XMP></body></html>") oDoc.close ' Close document. End Sub ]]> </script> </job>