Find path to application 
Author Message
 Find path to application

Is there any easy way to find the path to an application in VB 5.0.
What I want to do is to is to find out where e.g. Excel is installed and
thereafter start Excel with the shell() function.

Thanks a lot
Vidar



Sun, 28 May 2000 03:00:00 GMT  
 Find path to application

Quote:
> Is there any easy way to find the path to an application in VB 5.0.
> What I want to do is to is to find out where e.g. Excel is installed and
> thereafter start Excel with the shell() function.

You can pass the following function any "excel" file, such as
"workfile.xls" and it will return the full name of the "associated"
program.  Assuming that EXCEL is associated with .xls files, this may do
the trick.

Declare Function FindExecutable& Lib "shell32.dll" Alias "FindExecutableA"
(ByVal lpFile$, ByVal lpDir$, ByVal lpResult$)

Public Function GetAssociatedProgram$(ByRef LookFor$)
    Dim Result$
    Dim x&
    Dim API_Result&
    Dim FileName$
    Dim PathName$
    Dim Temp$

    Result$ = Space$(3000)

    x& = StringFindLast&(LookFor$, "\")
    If x& > 0 Then
      PathName$ = Left$(LookFor$, x&)
      FileName$ = Mid$(LookFor$, x& + 1)
    Else
      x& = StringFindLast&(LookFor$, ":")
      If x& > 0 Then
        PathName$ = Left$(LookFor$, x&)
      End If
      FileName$ = Mid$(LookFor$, x& + 1)
    End If

    API_Result& = FindExecutable&(FileName$, PathName$, Result$)
    If API_Result& > 32 Then
       API_Result& = InStr(Result$ & Chr$(0), Chr$(0))
       GetAssociatedProgram$ = Trim$(Left$(Result$, API_Result& - 1))
    Else
       GetAssociatedProgram$ = ""
    End If

End Function

Public Function StringFindLast&(ByRef InString$, ByRef FindPart$, Optional
StartPos As Long = 1)
   ' Finds the last occurence of a substring.
   Dim FoundPos&

   FoundPos& = InStr(StartPos, InString$, FindPart$)
   If FoundPos& > 0 Then
      StringFindLast& = lngMax&(FoundPos&, StringFindLast&(InString$,
FindPart$, FoundPos& + 1))
   Else
      StringFindLast& = 0
   End If
End Function

Public Function lngMax&(ByRef x&, ByRef y&)
   If x& > y& Then lngMax& = x& Else lngMax& = y&
End Function



Sun, 28 May 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Finding Application path of VB .Net project

2. Finding the application path

3. Finding application path

4. How to Find Installed Application Path

5. Finding default file type application path

6. Setting / finding path to an Application

7. Finding the path to the application

8. Finding an application's executable name and path

9. Long Path Names give Runtime error 76 - Path not found

10. Setting the path to the path of the current application

11. using application path (app.path)

12. Application Setup Wizard Says D:\<path>\D:\<path>\target.exe

 

 
Powered by phpBB® Forum Software