Questions similar to this appear on the Bentley Discussion Groups. This problem appeared in the MicroStation Programming Forum.

Q

Windows cmd.exe

A One answer to the question is to use Visual Basic for Applications (VBA). VBA is part and parcel of MicroStation V8. VBA provides extensive functionality, which you can extend by referencing built-in VBA methods, and even by calling the Win32 native application programming interface (API) directly.

The way to 'execute' a batch file is to give its path to the Windows built-in command executable cmd.exe. The way to persuade the operating system to do something with a batch file is to put those ideas together like this …
Shell("cmd.exe /k batchfile.bat")

Locating cmd.exe

Unfortunately, things aren't always as simple as we would like, because Shell() can't itself divine the location of the executable file. The VBA project ShellBatch.mvba takes care of those details. The key is knowing that cmd.exe is located in a Windows folder that you can find by getting the value of Windows environment variable WinDir.

Download ShellBatch.ZIP

Download ShellBatch

Download ShellBatch.ZIP (which contains ShellBatch.mvba) and run it by following these instructions …

  1. Copy ShellBatch.mvba to one of the folders in your computer's VBA search path (MS_VBASEARCHDIRECTORIES).
    C:\Program Files\Bentley\Workspace\Standards\VBA is a good choice
  2. Open MicroStation's key-in window from the Utilities menu
  3. Start your batch file with the following key-in …
    vba run [ShellBatch].Module1.Main batch file path
    where batch file path is the fully-qualified path to your .bat file