/**
* Name: enviro.js
* Author: Daren Thiel
* Date: 5 March 2000
* Web site: http://www.winscripter.com
*
* Comments: Creates an HTML file with three tables that
* displays all the Environment variables.
*
**/
// HTML output file
var outputfile = "enviro.html";
// Create Shell Object to access environment variables
var shell = WScript.CreateObject( "WScript.Shell" );
// Create File System Object to write to file.
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
// Create 'collection' variables to hold each of the environments
var sys = shell.Environment( "SYSTEM" );
var user = shell.Environment( "USER" );
var proc = shell.Environment( "PROCESS" );
// Open the output file for writing, create if necessary
var f = fso.OpenTextFile( outputfile, 2, true );
// Function call to write HTML header to output file
writeHeader();
// Function call to loop through and write out each
// environment collection
showEnvironment( sys, "SYSTEM" );
showEnvironment( proc, "PROCESS" );
showEnvironment( user, "USER" );
// Function call to write HTML footer
writeFooter();
// Utility function to make popups easier
function show( msg )
{
WScript.Echo( msg );
}
// Function to loop through environment collection
// obj - Collection variable that holds environment variables
// title - title to write to HTML table
function showEnvironment( obj, title )
{
// Write the start of our table
f.WriteLine( "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">" );
// Write the first table row which contains our title
f.WriteLine( "<tr><td colspan='2' style='background:blue; color:white;'>" );
f.WriteLine( "<center>" + title + "</center></td></tr>" );
// Try and Catch errors
try
{
// Create an enumerator to make it easier to move through a collection
var e = new Enumerator( obj );
// Loop through the enumerator
for( ; !e.atEnd() ; e.moveNext() )
{
// Write the results of function addrow to file
f.WriteLine( addrow( e.item() ) );
}
// Write the end of our table
f.WriteLine( "</table><br><br><br>\r\n\r\n" );
}
catch( e )
{
// Display any errors
show( e.description );
}
}
// Function to create a complete HTML table row
function addrow( viro )
{
// I used this method to split the strings since there can be
// environment variable that contain a '=' more than once.
// Slice up the string - retrieving Environment variable name
var evar = viro.substring( 0, viro.indexOf( "=" ) );
// Slice up the string - retrieving Environment variable value
var val = viro.substring( (viro.indexOf( "=" ) + 1) );
// Create variable to hold HTML table row data
// Place the Environment variable name in first cell
// Place the value in the second cell
var row = "<tr>\r\n";
row += "<td style='background:lightblue;'>" + evar + "</td>\r\n";
row += "<td>" + val + "</td>\r\n";
row += "</tr>\r\n";
// return the table row
return( row );
}
// Function to write HTML header. I added some styles to make it look
// a little more pleasing.
function writeHeader()
{
f.WriteLine( "<html>" );
f.WriteLine( "<head>" );
f.WriteLine( "<title>Environment Variables</title>" );
f.WriteLine( "<style>" );
f.WriteLine( "BODY { font-family:verdana; font-size:9pt; }" );
f.WriteLine( "TD { font-family:verdana; " );
f.WriteLine( "font-size:9pt; border-bottom: thin ridge blue; }" );
f.WriteLine( "</style" );
f.WriteLine( "</head>" );
f.WriteLine( "<body>\r\n\r\n" );
}
// Function to write HTML footer
function writeFooter()
{
f.WriteLine( "\r\n</body>\r\n" );
f.WriteLine( "</html>" );
}