Home
32 Bit dBase
Misc.
Links
Contact

Windows Scripting Host

Microsoft® Windows® Script is a comprehensive scripting infrastructure for the Windows platform. Windows Script provides script engines, Visual Basic® Scripting Edition, and Microsoft JScript®, which can be embedded into Windows applications and an extensive array of supporting technologies that make it easier for users to script Windows applications.

WSH 5.1 is included in W2K and is also installed with an IE5.01 install/upgrade.
WSH 5.5 is installed with an IE5.5 install/upgrade.
WSH 5.6 is included in WinXP and is also installed with an IE6 install/upgrade.

Windows 5.6 Scripting Host Download from Microsoft
Microsoft WSH Documentation

You can also download Windows Scriping Host here from my server
WSH for Win 2k
WSH for Win 9X
Here is a dBase program to test the current install and update it to version 5.6 if needed. Install_WSH.prg
It uses the 2 WSH downloads above.

So how do we use it with dBase?
Lets start out with something simple:

oFSO = new OleAutoClient("Scripting.FileSystemObject")
WindowsFolder = oFSO.GetSpecialFolder(0).path
SystemFolder = oFSO.GetSpecialFolder(1).path
TempFolder = oFSO.GetSpecialFolder(2).path
TempName = oFSO.getTempName() // return a temporary file name
release object oFSO
oFSO = NULL
			  

In the above code, we access the FileSystemObject using dBase's OleAutoclient.
As you can see following the code, we are able to get three of the special folder names from Windows just by referencing them by way of the GetSpecialFolders function and passing a parameter.
0 - the windows folder, 1 - the system folder, 2 - the temporary folder
We can also a unique temp file name by using the method getTempName().
While the dBase function fUnique() is actually a better command for this purpose, I used it here as an example of the abilities of the FileSystemObject.
Inspecting the fileSystemObject we can see more abilities that can expand the usability of dBase.

oFSO = new OleAutoClient("Scripting.FileSystemObject")
inspect(oFSO)			  
			  

Under the properties tab, we find a "drives" object. Clicking on that, we find the number of drives in our machine as the property "count". Lets access that object.
oDrives = oFSO.drives			
			
The drives object is a zero based array and each drive has multiple properties. One of which is "path". So let's flip though our array getting all the drive paths.
for i = 0 to oDrives.count -1
   ? oDrives[i].path
endfor
			
In addition to the "path" property of each drive, we also have many others.
for i = 0 to oDrives.count -1
	? oDrives[i].driveLetter
	? oDrives[i].path
	? oDrives[i].driveType
	? oDrives[i].fileSystem
	? oDrives[i].availableSpace
	? oDrives[i].freeSpace
	? oDrives[i].TotalSize
	? oDrives[i].serialNumber
	? oDrives[i].volumeName
	? oDrives[i].ShareName
endfor
			

Wow. That is a lot of stuff that you are able to get so easily from within dBase. And no crazy API calls.

Some information can be used as is while other information needs a little translation such as the driveType property. Here is a small function to translate the number returned into something more understandable.

function getDriveType
parameters lnDriveType
  do case
	 case lnDriveType=0
		lcDriveType = [Unknown]
	 case lnDriveType=1
		lcDriveType = [Removable]
	 case lnDriveType=2
		lcDriveType = [Fixed]
	 case lnDriveType=3
		lcDriveType = [Network]
	 case lnDriveType=4
		lcDriveType = [CD-ROM]
	 case lnDriveType=5
		lcDriveType = [RAM-disk]
		otherwise
		lcDriveType = [Unknown]
  endcase
  return lcDriveType

At this point let's list some differnt objects available and what they can be used for:

The Network object enables you to access information about your network or map network drives and map printers. ("WScript.Network")

File System Object (FSO), File system manipulation / Information, including copying files and folders, getting information, reading/writing files. ("Scripting.FileSystemObject")

The Shell object creating shorcuts, getting SpecialFolder paths, registry read/write, environment variables, run programs.("WScript.Shell")

And I have touched upon what you can do.