Microsoft KB Archive/176876

= How To Find VB32.EXE Without Searching the Hard Drive =

Article ID: 176876

Article Last Modified on 7/16/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q176876



SUMMARY
The sample code below demonstrates how to find the location of VB32.EXE by checking the registry rather than searching the entire hard drive.



MORE INFORMATION
Because customers occasionally install Visual Basic with a pathname other than the default suggested by SETUP, it may be necessary to search for the directory in which VB32.EXE has been installed. While simply searching the local hard drive with an equivalent to DIR/S serves in most circumstances, the presence of multiple large volumes makes a brute-force search of all the directories on each volume impractical.

Because Visual Basic Setup stores the fully-qualified path name to VB32.EXE under the key:

"HKEY_LOCAL_MACHINE\Software\Classes\VisualBasic\Shell\Open\command,"

it is a fairly simple task to obtain that pathname with the RegQueryValueEx API.

Step-By-Step Instructions
 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.

