/*EnvironBlockApplet for MS Win32 uses J/Direct to display the entire win32 environment variable block. M. Gallant 01/12/2002 */ import java.awt.*; import com.ms.security.*; import com.ms.win32.*; public class EnvironBlockApplet extends java.applet.Applet { TextArea ta = new TextArea(25, 100) ; public void init() { add(ta) ; try { if (Class.forName("com.ms.security.PolicyEngine") != null) // get permissions PolicyEngine.assertPermission(PermissionID.SYSTEM); ta.setText("------------- Environment Variables ------------\n\n" + getEnvBlock()) ; } catch (Throwable cnfe) { } } /** * Gets the entire environment variable block * @return The value of the named environment variable, or * null if no such variable exists */ private final String getEnvBlock() { // Allocate string buffer for return value StringBuffer value = new StringBuffer(2000); // Try to retrieve environment variable block via J/Direct int chars = GetAllEnvars(value, value.capacity()+1); // terminating null character added to buff capacity by J/Direct // If it was not large enough, reallocate buffer and retry if (chars > (value.capacity()+1)) //if buffer too small, GetAllEnvars returns required buffer size including C null. { System.out.println("\n" + value.capacity() + " character StringBuffer not large enough! expanding to " + (chars-1) + " characters\n\n") ; value.ensureCapacity(chars-1); chars = GetAllEnvars(value, chars); } // System.out.println("Characters read (including added after lines) " + chars) ; return value.toString(); } /** @dll.import("MIGUTILSLIB", ansi) */ static native int GetAllEnvars(StringBuffer buf, int size); public void paint(Graphics g) { // black border around applet panel g.setColor(Color.black) ; g.drawRect(0,0,this.getSize().width-1, this.getSize().height-1) ; } }