Günter Born

WSHShellExtend Programmer's Reference

The ActiveX control provides methods to access the Windows shell (provides some Shell API calls for scripts). This enables your scripts to use new features like print any registered file type (if a print verb is defined), empty recycle bin, activate verbs on filetypes or use the Windows open and save as dialogs (without installing a licensing software like Visual Basic).

The techniques to implement this control was discussed within my book "Inside Windows Script Host" (Microsoft Press Germany). The OCX file (see below) is released to the public in the internet.

Version Info

Version 1.0 of WSHShellExtend.ocx , which is available for download now. Currently the control supports a couple of methods to access the Windows shell.

WSHShellExtend object model

The ActiveX control WSHShellExtend (WSHShellExtend.ocx) contains the object ShellExtension, which extends the Windows Scripting Host with methods to access the shell.

Using the object

The object may be created in VBScript with the following statement:

Dim oShellEx
Set oShellEx = WScript.CreateObject("ShellExtension.ShellObjects")

and in JScript with the following statement:

var oShellEx = WScript.CreateObject("ShellExtension.ShellObjects");

Then you may use the object variable oShellEx to access the methods and properties.

The WSHShellExtend methods

Till now I haven't finished an English languaged document describing the methods exposed by this object. Please see the sample files shipped within the ZIP archive to find out how to use the methods.

The following code listing demonstrates how to open a Windows Open dialog box. The control enables the script to call API functions provided in comdlg.dll using methods.

''************************************************
' File:   Open.vbs (WSH-sample in VBScript) 
' Author: G. Born
'
' Demonstrate how to call Open dialog in comdlg.dll
' using an ActiveX control.
'************************************************
Option Explicit

Dim oShExt, code

' create object reference
Set oShExt = WScript.CreateObject("ShellExtension.ShellObjects")

' now we set the properties of the dialog
oShExt.WSHDialogTitle = "Born's Open dialog"  ' Title
oShExt.WSHDialogFilter = "All files (*.*)" & chr(0) & _
                         "*.*" & chr(0) & _
                         "VBScript files (*.vbs)" & chr(0) & _
                         "*.vbs" & chr(0) & _
                         "JScript files (*.js)" & chr(0) & _
                         "*.js" & chr(0) & _
                         "WSC files (*.wsc)" & chr(0) & _
                         "*.wsc" & chr(0)

oShExt.WSHDialogFilterIndex = 2  ' 2nd entry selected

oShExt.WSHDialogInitDir = "C:\"  ' empty string = current directory

If oShExt.WSHShowOpen () <> 0 Then 
 MsgBox "File " & oShExt.WSHDialogFile
Else
 MsgBox "Sorry, no file selected"
End if

'*** End

Terms of use

The WSHShellExtend ActiveX control comes AS-IS without any warranty and support. Use the control at your own risk. In no case the author will be liable for damages or losses or whatever else resulting from the use of this component. The OCX module may be freely distributed under the condition that this Programmers Reference is included and that the WSH Bazaar with its URL http://www.borncity.de is mentioned as the source of the control.

Download and install

Download the OCX file and install it on your machine. Because the ActiveX control was developed under VB, it needs the VB 5 run-time libraries. If you have ever installed the WSHExtend control, these run-time libraries are available. Then is is sufficient to download the ZIP-archive, unzip the files into a local folder and run RegSvr32.exe to install the control. Further details may be found in the file Readme.txt shipped within the ZIP archive.

After installing WSHShellExtend you can use the object and its methods as described above.
top


by (c) Günter Born changed 16-August-2000