
spnh 1.0b (beta)
A console Win32 program which spawns other programs in a hidden window
Copyright (C) 1997  Yoram Last

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

The author of this program can be contacted by e-mail at ylast@mindless.com.


USAGE: 
=======

Place the executable anywhere you like, and use it from the command line,
from scripts, from shortcuts, or through registry-based file association.

This program was created mainly for the purpose of extending the CGI
capabilities of Microsoft's "Personal Web Server for Windows 95" (PWS).
(See more on this below.) For other (non CGI related) tasks of hiding/unhiding
windows we recommend using "HideWindow" by Adrian Lopez (free binary), which
can be obtained from http://www.winsite.com/info/pc/win95/desktop/hidewndw.zip/
(Note, however, that some things get broken if you try to spawn CGI programs
through "HideWindow", which is why "spnh" had been created).


COMMAND LINE SYNTAX:
=====================

spnh "<commandline>"

Where <commandline> includes the name of the program you wish to run hidden,
along with any command line arguments to it.

Example: spnh "notepad somefile.txt"
This will run notepad, opening somefile.txt, in a hidden window (so you
will not see anything).

Note that you must use the double quotes if <commandline> contains any
spaces. Moreover, if <commandline> itself contains any double qoutes,
they should be preceded by backslashes (e.g.,
spnh "notepad \"a filename with spaces.txt\"").


USING spnh WITH MICROSOFT'S PWS:
=================================

Note: This explanation only relates to the the product called
"Personal Web Server 1.0a for Windows 95", which can be downloaded
from Microsoft's web site as an IE add-on. (Some versions of Frontpage
came with a different server that was also called "Personal Web Server".)

The standard way (used by most Win32 web servers) of running (standard) CGI
programs is as console processes. This provides them with the full I/O
capabilities (e.g., the ability to communicate with other programs), but it
also has a performance price. Microsoft's PWS takes a non-conventional
approach to this issue, and (at least by default) spawns CGI programs
without a console. This has one major advantage: CGI programs that are
spawned this way execute much faster and consume far less system resources.
However, it also has a number of disadvantages, such as:

1. 16 bit programs can't be spawned, and in particular, batch (.bat)
  files can't be used as CGI programs.

2. The spawned programs can't communicate with other programs through
  standard I/O (STDIN/STDOUT) channels, and in particular, they can't
  communicate with the DOS (command.com) shell.

'spnh' solves these problems by letting the server spawn CGI programs with
a full (hidden) console. In order to use it for this purpose you need to
decide on the extensions of programs (scripts) that you want to be spawned
through 'spnh' and create appropriate registry string values (one for each
extension) in the registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3Svc\Parameters\Script Map

The name of each registry value should be the appropriate extension (e.g.,
.bat). The data should consist of the full path to 'spnh' followed by the
<commandline> that needs to be executed. The <commandline> should contain
two %s wildcards, the first of which stands for the program (or script) that
is called for execution and the second stands for any command line arguments
to it.

Examples:

1. In order to have Perl scripts (.pl files) execute with a full console, create
a (string) registry value with the name .pl and then set the data to be:

The:\Full\Path\To\spnh.exe "perl %s %s"

This should work if perl.exe is in your 'PATH'. In any event, it is better to
replace 'perl' by the full path to perl.exe.

Remark: If you installed "Perl for Win32" after installing PWS, you might already
have a .pl registry value with data associating this extension with PerlIS.dll.
PerlIS.dll is an ISAPI (not CGI!) Perl interpreter. It delivers even better
performance than non-consoled CGI, but it is more restricted in terms of what it
can do. The best overall solution is to have three different extensions for Perl
scripts. One (e.g., .pl) for ISAPI scripts, one (e.g., .pln) for CGI scripts that
do not require a console, and the third (e.g., .plc) for CGI scripts that do
require a console (e.g., for scripts that make calls to the DOS shell). You can
set things up in this way by setting three registry values as follows:

NAME                         DATA

.pl                The:\Full\Path\To\PerlIS.dll %s %s
.pln               The:\Full\Path\To\perl.exe %s %s
.plc               The:\Full\Path\To\spnh.exe "The:\Full\Path\To\perl.exe %s %s"

(Note that Perl scripts can have any extension you want. The standard .pl is a
useful convention, but it is not necessary for the scripts to run.)

2. In order to be able to use .bat files as CGI scripts create a registry value
having the name .bat and the data:

The:\Full\Path\To\spnh.exe "The:\Full\Path\To\spnh.exe \"%s %s\""

Why do we need spnh.exe twice? Mainly, because it will not work properly otherwise.
One can think of spnh.exe as being both a hidden console spawner and a script
interpreter for .bat files (which needs to have a full console in order to work
properly).

In case you do not have previous experience with the registry editor, and you find
the above examples unclear; let us explain in detail what needs to be done in order
to set up example 2 (.bat). This explanation assumes that you have spnh.exe in your
C:\windows directory, which is a good place to put it in. If you prefer to put it
elsewhere, you should change things accordingly.

a) Launch the registry editor 'regedit' (this can be done by choosing 'Run' from
  the start menu, typing regedit, and clicking 'ok').

b) Locate the key 'HKEY_LOCAL_MACHINE' and click the '+' besides it to expand it,
  then locate and expand 'System', etc., untill you expand the key

  HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3Svc\Parameters

  Now click on the key 'Script Map'.

c) Now, from the editor's 'Edit' menu, choose 'New' and then 'String Value'.
  type:

  .bat

  and then click the mouse away from the registry value. Then right-click on the
  newly created value, and choose 'Modify'. Type

  c:\windows\spnh.exe "c:\windows\spnh.exe \"%s %s\""

  and click 'OK'. You can now close the registry editor.

d) In order for the change to take effect: stop your server and restart it.


TECHNICAL SUPPORT:
===================

No support of any kind is provided for this program, and the author
does not promise to answer e-mail messages related to it. Bug reports
and feedback (of any kind) to ylast@mindless.com would be appreciated.

