Introduction

MicroStation® is produced by Bentley Systems. It is a 3D computer-aided-design (CAD) tool for Windows.

MicroStation its own development tools that are used to create add-in applications. However, those applications don't help if you want to find out about MicroStation without executing the product.

For example, you may want to determine the current version of MicroStation, or discover its installed location. You may want to add data to a MicroStation workspace, in which case you want to know where its workspace folder is located.

Questions about Windows and MicroStation. Questions about MicroStation's installed location.

  1. What is VB Script?
  2. What is CScript.exe?
  3. How do I run or execute a VB Script?
  4. What command-line options does CScript provide??
  5. How do I find the current version of MicroStation using VB Script?
  6. How do I determine whether I have a 32-bit or 64-bit version of Windows?

VB Script and CScript.exe

One route to find answers to those questions is to use VB Script, executed in the context of Windows script host, cscript.exe, which is part of your Windows operating system installation. The following paragraph is copied from Microsoft Technet …

Using the command-based script host

Cscript.exe is a command-line version of the Windows Script Host that provides command-line options for setting script properties.

With Cscript.exe, you can run scripts by typing the name of a script file at the command prompt. Like Microsoft Internet Explorer, Windows Script Host serves as a controller of Windows Script compliant scripting engines, but Windows Script Host has very low memory requirements. Windows Script Host is ideal for both interactive and non-interactive scripting needs, such as logon scripting and administrative scripting.

Windows Script Host supports scripts written in VBScript or JScript. When you start a script from your desktop or from the command prompt, the script host reads and passes the specified script file contents to the registered script engine. The script engine uses file extensions (that is, .vbs for VBScript and .js for JScript) to identify the script. As a result, you do not need to know the exact programmatic identifier (that is, the ProgID) of the script engine. The script host maintains a mapping of script extensions to programmatic identifiers, and uses the Windows XP association model to start the appropriate engine for a given script.

Q How do I run VB Script?

A Save your script as a text file having a .vbs file extension. Open a Windows command prompt, then key-in
cscript example.vbs

Q How do I see VB Script options?

A Open a Windows command prompt, then key-in
cscript /?

CScript Command-Line Options

To run scripts using the command-line-based script host

You can run scripts with the command-line-based script host by typing the following at the command prompt …

cscript [script name] [host options] [script arguments]

Where:

Find out more about running scripts on Microsoft's TechNet web site.

Q How do I determine whether I'm running 32-bit or 64-bit Windows?

A MicroStation v8i and its predecessors are 32-bit applications. When searching the Registry for information about 32-bit applications we need to be aware of the 'bitness' of the operating system. That is, are we running a 32-bit version or a 64-bit version of Windows? It's necessary to know because, when searching the HKEY_LOCAL_MACHINE\SOFTWARE node on a 64-bit version of Windows, 32-bit application data are under the Wow6432Node sub-tree. For a 32-bit version of Windows, Wow6432Node does not exist.

Note that the bitness of the operating system is not the same as the bitness of the processor. If your computer was built after 2000 then it almost certainly has a 64-bit processor. However, depending on the operating system installed, you may have either a 32-bit computer or a 64-bit computer irrespective of its processor's capability. It's important therefore to test the operating system's capability, not what hardware is provided.

For example, some sites advise checking for Registry value HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0. However, that tells you only the processor's address width, not what is implemented by the operating system on that computer.

Testing Operating System Bit-Ness

Here's a VB script function that checks for a 32-bit operating system …

Function Is32BitOS()
    Const Path = "winmgmts:root\cimv2:Win32_Processor='cpu0'"
    Is32BitOS = (GetObject(Path).AddressWidth = 32)
End Function

Here's how you might use that function …

If Is32BitOS Then
	WScript.Echo "Operating system is 32-bit "
End If

For detecting a 64-bit operating system, here is a similar pair of examples …

Function Is64BitOS()
    Const Path = "winmgmts:root\cimv2:Win32_Processor='cpu0'"
    Is64BitOS = (GetObject(Path).AddressWidth = 64)
End Function
If Is64BitOS Then
	WScript.Echo "Operating system is 64-bit "
End If

Q How do I find the current version of MicroStation using VB Script?

A Before we answer that question, we first need to see what the answer should be. The route to that answer is via the Windows Registry, which is the Windows database of applications, settings and other meta-data. Fortunately, Microsoft provide the StdRegProv class, which makes it possible to query the Registry.

There's some mumbo-jumbo required. If you want to find out more about StdRegProv, consult the Microsoft web site.

The information we want in the Registry is found in the HKEY_CLASSES_ROOT hive. The path to MicroStation's class ID is Bentley.MicroStation.Application\CLSID and we want its default value. Here's the VB script to obtain that class ID …

const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set oReg=GetObject( _
   "winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")
strKeyPath = "Bentley.MicroStation.Application\CLSID"
strValueName = ""
oReg.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, strValueName, strValue
WScript.Echo "MicroStation CLSID: " & strValue

Having found MicroStation's class ID we can interrogate the Registry further to obtain MicroStation's installation folder and workspace folder. Note that the following code is looking for the 32-bit version of MicroStation on a 64-bit operating system. The information we want is beneath the Wow6432Node node of the HKEY_LOCAL_MACHINE hive …

const HKEY_CLASSES_ROOT = &H80000000
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject( _
   "winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")
' MicroStation CLSID
strKeyPath = "Bentley.MicroStation.Application\CLSID"
strValueName = "" ' We want the default value
oReg.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, strValueName, strCLSID
WScript.Echo "MicroStation CLSID: " & strCLSID

'	MicroStation workspace folder
strKeyPath = "SOFTWARE\Wow6432Node\Bentley\Installed_Products\" & strCLSID
strValueName = "WorkspacePath"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strWorkspaceFolder
WScript.Echo "Workspace folder: " & strWorkspaceFolder

'	MicroStation install folder
strKeyPath = "SOFTWARE\Wow6432Node\Bentley\Installed_Products\" & strCLSID
strValueName = "ProgramPath"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strProgramFolder
WScript.Echo "MicroStation folder: " & strProgramFolder

'	MicroStation version
strKeyPath = "SOFTWARE\Wow6432Node\Bentley\Installed_Products\" & strCLSID
strValueName = "Version"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strVersion
WScript.Echo "MicroStation version: " & strVersion

When I run the above script on my computer having a 64-bit operating system, I see the following (your results are likely to be different) …

MicroStation folders revealed by VB Script

Determine the Right Registry Path for your Operating System Bit-Ness

If you want a script to execute on both 64-bit and 32-bit operating systems, then you must account for the presence or absence of the Wow6432Node node. We can do that by detecting the operating system bit-ness and writing a function to construct a valid path. Something like this …

Function SoftwarePath6432 ()
    If Is32BitOS Then
        SoftwarePath6432 = "SOFTWARE\Bentley\Installed_Products\"
    ElseIf Is64BitOS Then
        SoftwarePath6432 = "SOFTWARE\Wow6432Node\Bentley\Installed_Products\"
    End If
End Function

Now the script to find the MicroStation folders will work with either 32-bit or 64-bit operating systems …

const HKEY_CLASSES_ROOT = &H80000000
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_USERS = &H80000003
const HKEY_CURRENT_CONFIG = &H80000005
strComputer = "."
Set oReg=GetObject( _
   "winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")
' MicroStation CLSID
strKeyPath = "Bentley.MicroStation.Application\CLSID"
strValueName = "" ' We want the default value
oReg.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, strValueName, strCLSID
WScript.Echo "MicroStation CLSID: " & strCLSID

'	MicroStation workspace folder
strKeyPath = SoftwarePath6432 ()  & strCLSID
strValueName = "WorkspacePath"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strWorkspaceFolder
WScript.Echo "Workspace folder: " & strWorkspaceFolder

'	MicroStation install folder
strKeyPath = SoftwarePath6432 ()  & strCLSID
strValueName = "ProgramPath"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strProgramFolder
WScript.Echo "MicroStation folder: " & strProgramFolder

'	MicroStation version
strKeyPath = SoftwarePath6432 ()  & strCLSID
strValueName = "Version"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strVersion
WScript.Echo "MicroStation version: " & strVersion

' Function definitions

Function SoftwarePath6432 ()
    If Is32BitOS Then
        SoftwarePath6432 = "SOFTWARE\Bentley\Installed_Products\"
    ElseIf Is64BitOS Then
        SoftwarePath6432 = "SOFTWARE\Wow6432Node\Bentley\Installed_Products\"
    End If
End Function

Function Is32BitOS()
    Const Path = "winmgmts:root\cimv2:Win32_Processor='cpu0'"
    Is32BitOS = (GetObject(Path).AddressWidth = 32)
End Function

Function Is64BitOS()
    Const Path = "winmgmts:root\cimv2:Win32_Processor='cpu0'"
    Is64BitOS = (GetObject(Path).AddressWidth = 64)
End Function