It assumes the Apache server has been configured to permit running of CGI scripts
and test folder vbs_test and file .htaccess have been created as explained on the introduction page.
The following are examples of valid Perl and VBScript shebang lines:
- '!C:/windows/system32/cscript –nologo
Note the two-character shebangs are #! and '!
Solution - Use wsf files
Solution to this problem is to use Windows script files (*.wsf) these are not engine-specific and act as a container. For Apache CGI scripts they have one import feature the first line of a script can use a two-character shebang. The shebang looks like this:
- '!C:/windows/system32/cscript –nologo - Note it is identical to a VBScript shebang.
Main features of wsf files:
- Include statements Incorporate functions from VBScript or JScript files into your Windows Script Host project.
- Multiple engines Use more than one scripting language per file.
- Type libraries Add constants to your code.
- Tools Edit files with any XML editor.
- Multiple jobs in one file Store all of your code in a single location.
Basic swf file format
'Comment <job> <script language="JScript" src="some_file.js"/> <script language="VBScript" src="some_file.vbs"/> <script language="JScript"> WSH.Echo("Hello world"); </script> <script language="VBScript"> WScript.Echo "Hello world" </script> </job>
To run wsf files as CGI scripts Apache needs to be configured to permit files with that extension.
Edit file \www\vbs_test\.htaccess
Add the extension .wsf to the AddHandler line as shown on right.
AddHandler cgi-script .vbs .wsf Options +ExecCGI
Every script must start with a shebang, wsf files use the VBScript shebang. This shebang informs Apache to use the command line interpreter and to suppress any logo text that is output by default. The first line any CGI script outputs must be a valid Content-type header of particular importance are the two new line characters these are mandatory.
'!c:/windows/system32/cscript //nologo <job> <script language="JScript"> WSH.Echo("Content-type: text/html \n\n"); WSH.Echo("Hello world"); </script> </job>
Hello world displayed in browser confirms correct operation.
Basic page template:
Basic page template is shown on right.
Note: Precede HTML single parameter quotes with a backslash for example style="color:red" becomes style=\"color:red\"
The script produces output as shown on right.
Generally the same banner and footer are used on every page
Banner CGI Test 10
Footer CGI Test 10
Where to next
Next page covers adding a banner and footer using wsf include files.