This article has been archived. It is offered "as is" and will no longer be updated.
The sample code below demonstrates how to find the location of VB32.EXE bychecking the registry rather than searching the entire hard drive.
Because customers occasionally install Visual Basic with a pathname otherthan the default suggested by SETUP, it may be necessary to search for thedirectory in which VB32.EXE has been installed. While simply searching thelocal hard drive with an equivalent to DIR/S serves in most circumstances,the presence of multiple large volumes makes a brute-force search of allthe directories on each volume impractical.
Because Visual Basic Setup stores the fully-qualified path name to VB32.EXEunder the key:
it is a fairly simple task to obtain that pathname with theRegQueryValueEx() API.
Open a new project. Form1 is created by default.
Add a Code Module and, in the General Declarations section, place the following code:
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _ (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As _ Long, ByVal samDesired As Long, phkResult As Long) As Long Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _ "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _ String, ByVal lpReserved As Long, lpType As Long, lpData As Any, _ lpcbData As Long) As Long Option Explicit Global Const HKEY_LOCAL_MACHINE = &H80000002 Global Const KEY_READ = &H20019 Global Const ERROR_SUCCESS = 0&
Add a CommandButton to the default form.
In the Click Event of the CommandButton, place the following code:
Dim RegKeyHandle As Long Dim RetVal As Long Dim KeyType As Long Dim Data As String * 255 Dim DataLen As Long RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _ "Software\Classes\VisualBasic\Shell\Open\command", _ 0, KEY_READ, RegKeyHandle) If RetVal <> ERROR_SUCCESS Then MsgBox "Can't Open Key" Else MsgBox "Opened It!" & vbCrLf & "Getting Default Value" DataLen = 512 RetVal = RegQueryValueEx(RegKeyHandle _ , vbNullString _ , 0 _ , KEY_READ _ , ByVal Data _ , DataLen) If RetVal <> ERROR_SUCCESS Then MsgBox "Missed It!" Else MsgBox Left(Data, DataLen) End If End If
Run the program. If Visual Basic is installed, the fully-qualified pathname to VB32.EXE appears in the message box.
"Visual Basic Programmer's Guide to the Win32 API", Daniel Appleman, PCMagazine Press; c1996.