httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jlwpc1" <>
Subject Windows Script Host
Date Tue, 26 Dec 2000 18:18:57 GMT


> Two, it's official ... we don't have anything useful on Win32 to help us with rewriting

>  (no sed, no nothing, by default) so we will require perl. Sorry to anyone that causes

> trouble for, but it's fairly unavoidable unless we want sed instead. 

Windows has built in script engines!

No need for
> awk -f < 0 ) { gsub( /@@ServerRoot@@/, serverroot ); print $$0 dstfl; 

xxxxxxxxxx  Cut test make file xxxxxxxxxx

# The default installation directory is \Apache. This can be changed
# with the INSTDIR macro, for example:
#   nmake /f INSTDIR="d:\Program Files\Apache" installr
# Note: this does *NOT* change the compiled in default "server root"

!IF "$(INSTDIR)" == ""
!MESSAGE Using default install directory \Apache

      @echo Now using as install directory $(INSTDIR)
      cscript apwinmk.js "$(INSTDIR)"
xxxxxxxxxx   END OF CUT MAKE FILE   xxxxxxxxxx

xxxxxxxxxx   CUT APWINMK.JS   xxxxxxxxxx

// Apache Windows Script Host test file called in make.

// Really this is just a JScript file running in WSH. Real WSH files use
// XML elements to call JScript or VBScript or PerlScript or CobolScript.

// Lets define some variables.
var s;     // This will hold most strings.

// Now we need the INSTDIR information from the make file that called us.

// Windows NT/2000 could just use these environment methods.
//var WshShell = WScript.CreateObject("WScript.Shell");
//WScript.Echo("WinDir is " + WshShell.ExpandEnvironmentStrings("%WinDir%"));
//WScript.Echo("INSTDIR is " + WshShell.ExpandEnvironmentStrings("%INSTDIR%"));

// But since Windows 95/98/98SE/ME have a hard time setting environment 
// variables via make files, then Apache Windows C Run Time Web Sever 
// developers will pass the INSTDIR variable on the command line to 
// this script file.

// Get the command line args.

var i, numargs = WScript.Arguments.length;
var objArgs = WScript.Arguments;
s = numargs;  

if (numargs < 2)
  s += " argument was passed to " + WScript.ScriptName + ". It was ";
  s += " arguments were passed to " + WScript.ScriptName + ". They were " ;

for (i = 0; i < numargs; i++)
  s += objArgs(i) + " ";

// To display the command line args, just
// remove the two slashes in the line below.

// We know the first argument (starting at zero) is the
// variable for INSTDIR, so store it away for latter use.
var instdir = objArgs(0);

// Now open the demo test file and display it.
// But first be safe and copy the file.

// We can create, delete, and move folders and files.

// There are LOTS of try...catch and if exists test.
// We will skip most of them for this demo.

// Make a dir on another drive (d:) for backup and copy the
// file (from e:) over to this backup dir. This backup dir
// could also be an environment variable or passed on the 
// command line as a argument to this file.

// Since while testing, we run and re-run this file 
// lets do some test!

// Contact the file system.
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FolderExists("d:\\test\\apbackup"))
if (!fso.FileExists("d:\\test\\apbackup\\apcon.txt.bak"));
  fso.CopyFile("apcon.txt", "d:\\test\\apbackup\\apcon.txt.bak");

// Now do some Regular Expressions methods on the test demo file.

var f1, r, f;
var filename = "apcon.txt"
var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;

// Can open in Unicode or ASCII, but defaults to ASCII.
// We will read the whole file but could do line
// by line.

// Read all the file and display to screen.
f1 = fso.OpenTextFile("apcon.txt", ForReading);
WScript.Echo( f1.ReadAll() );

// Now demo the RegExp on apcon.txt file.

// Read from this file.
f1 = fso.OpenTextFile("apcon.txt", ForReading);

// Write to this file.
f2 = fso.CreateTextFile("ap.txt", ForWriting);
// RegExp stuff.
var re = /Win32/igm;
var rv = "";

while (!f1.AtEndOfStream)
  r =  f1.ReadLine();

  rv = r.replace(re,"Windows C Run Time");




// Let do some more RegExp stuff.

//Open the file we just wrote to for reading.
f1 = fso.OpenTextFile("ap.txt", ForReading);
var tt = f1.ReadAll();

// All done with ap.txt file - for now!

// Do the RegExp stuff.
re = /problems/igm;
rv = tt.replace(re,"troubles");

// Copy the changes to do more RegExp stuff!
tt = rv;

re = /@@ServerRoot@@/igm;
rv = tt.replace(re,instdir);

// Copy the changes to do more RegExp stuff!
tt = rv;

re = /test/gm;
rv = tt.replace(re,"builtin scripting test");

// Copy the changes to do more RegExp stuff!
tt = rv;

// Get the short path name for the server root.

f = fso.GetFolder(instdir);
s = "The short path for Server Root is: " + f.ShortPath + " (8.3) size";
re = /root/gm;
rv = tt.replace(re,"root!\n" + s);

// All done with RegExp on apcon.txt so display difference.
WScript.Echo( rv );

// Might as well save what we did after we read the whole file,
// so overwrite the file with the changes.

f1 = fso.CreateTextFile("ap.txt", true);

// End of file apwinmak.js

xxxxxxxxxx   END OF CUT APWINMK.JS   xxxxxxxxxx

xxxxxxxxxx    OUTPUT   xxxxxxxxxx

E:\scripts\aptest>make -DINSTDIR="E:\Test Programs\Apache Group\Web Servers" -f
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
Now using as install directory E:\Test Programs\Apache Group\Web Servers
        cscript apwinmk.js "E:\Test Programs\Apache Group\Web Servers"
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2000. All rights reserved.

This is a Apache Win32 Web Server test file.
@@ServerRoot@@ is the server root!
This file will demo reading and writing files
for Apache Win32 Web Server make "problems".
Server Root is @@ServerRoot@@.
End of Apache Win32 Web Server test file.

This is a Apache Windows C Run Time Web Server builtin scripting test file.
E:\Test Programs\Apache Group\Web Servers is the server root!
The short path for Server Root is: E:\TESTPR~1\APACHE~1\WEBSER~1 (8.3) size!
This file will demo reading and writing files
for Apache Windows C Run Time Web Server make "troubles".
Server Root is E:\Test Programs\Apache Group\Web Servers.
End of Apache Windows C Run Time Web Server builtin scripting test file.


xxxxxxxxxx    END OF OUTPUT   xxxxxxxxxx

QUOTING Microsoft PR Below:

Microsoft Windows Script Host is a language-independent scripting host for ActiveX scripting
engines.  It brings simple, powerful, and flexible scripting to the Windows 32-bit platform,
allowing you to run scripts from both the Windows desktop and the command prompt.

Windows Script Host is ideal for non-interactive scripting needs such as logon scripting,
administrative scripting, and machine automation.

Windows Script Host provides ActiveX interfaces for direct manipulation of script execution,
as well as helper functions for other actions. The Windows Script Host Reference documents
elements, methods, objects, and properties with which you can accomplish tasks such as the
Print messages to the screen 
Run basic functions such as CreateObject and GetObject 
Map network drives 
Connect to printers 
Retrieve and modify environment variables 
Modify registry keys 
Regular Expressions

My PR addon below:

Create, delete, read and write files and folders 
Get user groups, etc.
Remote access,
Shell access,
And much more..

Back to QUOTING Microsoft PR 

Windows Script Host is integrated into Windows 98, Windows 2000 Professional, and Windows
2000 Server. Version 2.0 includes the VBScript and JScript scripting engines. In the future,
other software companies may provide ActiveX scripting engines for languages such as PerlScript,
TCL, REXX, and Python

End QUOTING Microsoft PR 

WSH upgrades are available for Windows 95 and Windows NT via IE upgrades, service packs, and
downloading each "script accessory" that is wanted or needed!

WSH 2.0 Tutorial
WSH Documentation

VBScript User's Guide
VBScript Documentation

FileSystemObject User's Guide
VBScript Run-Time Library Reference [FileSystemObject/Dictionary]

JScript User's Guide
JScript Documentation

WSC Tutorial
WSC Documentation

Current version is 5.5 but version 5.6 (beta) is out - this is what I used for this test on
an old Windows 95 computer (I know how Apache always uses OLD stuff)! :)

Mmmm,  WSH and registry read/write, folder create and VBScript input boxes and message boxes
- sounds a lot like the start of an Apache Windows WSH (xml/jscript/vbscript) Command line
Installer or even a HTA IE Apache Installer or both!  :)


View raw message