Günter Born

WSHSystem Programmers Reference

This reference describes the WinSys object model of the WSHSystem ActiveX control. WSHSystem is an ActiveX control which provides some methods to retrieve system information from a WSH script. The techniques to implement this control was discussed within my book Inside Windows Script Host. I saw several requests for methods for retrieving system information like the Windows version. Therefore I have implemented a control to support these requests. The OCX file (see below) and this reference are released to the public in the internet. In Windows 2000 I recommend using WMI to query these information.

Version Info

The initial release of WSHSystem is version 1.0, which is available for download now. Currently the control supports only one method to retrieve the Windows version. But there are also plans to extend the control to retrieve other system information (like the processor type, the memory size and so on)

The WinSys object model

The ActiveX control WSHSystem (WSHSystem.ocx) contains the object WinSys, which extends the Windows Scripting Host with methods to retrieve system informationform. Below is a short reference of the WinSys object model, describing the methods and properties.

Using the object

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

Dim objAdr
Set objAdr = WScript.CreateObject("WSHSystem.WinSys")

and in JScript with the following statement:

var objAdr = WScript.CreateObject("WSHSystem.WinSys");

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

The WSHOsSysInfo method

This method allows you to retrieve the operating system data. The method has no parameters and may be invoked with the following statement.

objAdr.WSHOsSysInfo 

After calling this method, you can read the Windows properties using the following statement:

objAdr.OsSysInfoValue(type)

The parameter type defines the requested value according to the following table:

Value Remark
1 Returns the major version of the operating system.
2 Returns the minor version of the operating system
3 Returns the build of the operating system
4 Returns the platform of the operating system:
0 = old WIN32
1 = WIN32 (Win 9X)
2 = WIN32 (NT )
5 A text string containing additional information.

If the platform is 2 and the major version is 4, we have Windows NT 4.0. Windows 2000 returns version 5.0. Windows 95 comes with platform code 1 and a version of 4.0. If the version 4.1 is returned for platform 1, we have Windows 98. The build may be extracted from the property by Anding the value with 0FFFH. A revision like (Windows 95 b or Windows 98 2nd editon) is indicated with a character returned in item 5. The following code listing retrieves the operating system version and shows the result within a dialog box.

'************************************************
' File:    WinVersion.vbs (WSH sample in VBScript) 
' Author:  Günter Born
'
'
' Retrieve OS-Version number
' Attention: Requires WSHSystem.ocx
' Check out Born's Windows Scripting Host Bazaar at:
' http://www.borncity.de
'
' In no way shall the author be liable for any
' losses or damages resulting from the use of this
' program. Use AS-IS at your own risk.
'
' The code is the property of the author. You may
' use the code and modify it, as far as this header
' remains intact. Further updates and other samples
' may be found on my site mentioned above.

'************************************************
Option Explicit

Const xMajorVer = 1
Const xMinorVer = 2
Const xBuild = 3
Const xPlatform = 4
Const xTxt = 5

Const VER_PLATFORM_WIN32s = 0
Const VER_PLATFORM_WIN32_WINDOWS = 1
Const VER_PLATFORM_WIN32_NT = 2

Dim objAdr, Text, Title, OSName

 Title = "Operating System Information - by Günter Born"
 Text = "Windows Properties" & vbCRLF

' Get a reference to the WSHExtend control
 Set objAdr = WScript.CreateObject("WSHSystem.WinSys")

 objAdr.WSHOsSysInfo               ' Get Windows-OS-Info

 Text = Text + "Platform "
' Estimate OS-Platform
 Select Case objAdr.OsSysInfoValue(xPlatform)
 Case VER_PLATFORM_WIN32_WINDOWS
  If objAdr.OsSysInfoValue(xMajorVer) = 4 _
   And objAdr.OsSysInfoValue(xMinorVer) = 0 Then
    Text = Text & "Windows 95"
  Else
    Text = Text & "Windows 98"
  End If

 Case VER_PLATFORM_WIN32_NT
  If objAdr.OsSysInfoValue(xMajorVer) = 5 _
   And objAdr.OsSysInfoValue(xMinorVer) = 0 Then
    Text = Text & "Windows 2000"
  Else
    Text = Text & "Windows NT 4.x"
  End If
 Case Else
  Text = Text & "---"
 End Select

 Text = Text & vbCRLF

' Extract other Operating System Properties
 Text = Text & "Version " & objAdr.OsSysInfoValue(xMajorVer)
 Text = Text & "." & objAdr.OsSysInfoValue(xMinorVer) & vbCRLF
 Text = Text & "Build " & (objAdr.OsSysInfoValue(xBuild) AND &HFFF) 
 Text = Text & " " & objAdr.OsSysInfoValue(xTxt) & vbCRLF

 MsgBox Text, vbOkOnly + vbInformation, Title

' End

Terms of use

The WSHSystem 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 RegisterOcx.bat to install the control.

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


by (c) Günter Born changed 10-June-1999