You can use the SearchPath API function.
The following code will search for an application in the way specified in the comments.
The Run dialog box however will also check this all keys in the registry under the following path:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
VB Code:
Private Declare Function SearchPath _
Lib "kernel32" Alias "SearchPathA" ( _
ByVal lpPath As String, _
ByVal lpFileName As String, _
ByVal lpExtension As String, _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String, _
ByVal lpFilePart As String) As Long
Private Function SearchFile(ByVal sFileName As String)
'This function will search after the file in the following order
' 1. The directory the app is loaded from
' 2. The active directory
' 3. Windows System directory (winnt\system32 or windows\system)
' 4. The Windows directory
' 5. The directories listed in the PATH environment variable
Dim sBuffer As String
Dim nLen As Long
sBuffer = Space$(260)
nLen = SearchPath(vbNullString, sFileName, vbNullString, _
Len(sBuffer), sBuffer, vbNullString)
SearchFile = Left$(sBuffer, nLen)
End Function
Private Sub Command1_Click()
'This is an example on how to call the code.
'If the file isn't found an empty string is returned
MsgBox SearchFile("notepad.exe")
End Sub
Best regards