Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetExecutableFile - Find the program associated to a document file
[ All Languages » VB »  Windows]

Total Hit ( 2751)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Function FindExecutable Lib "shell32.dll" Alias _
  "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, _
  ByVal sResult As String) As Long

Private Const MAX_PATH = 260
Private Const ERROR_FILE_NO_ASSOCIATION = 31&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_FILE_SUCCESS = 32&

' Return the name and path of the EXEcutable file that
' is associated to the specified file.
' Returns a null string if there is no such associated file,
' and raises an error if the file or the path hasn't been found.

Public Function GetExecutableFile(ByVal FileName As String) As String
  Dim sPath As String, sFile As String
  Dim lPos As Long
  Dim sResult As String

  ' get the file's name and path, exit if no path is there
  lPos = InStrRev(FileName, "\")
  If lPos = 0 Then Exit Function
  sPath = Left$(FileName, lPos)
  sFile = Mid$(FileName, lPos + 1)
  
  ' call the FindExecutable API function and
  ' process the return value
  sResult = Space(MAX_PATH)
  Select Case FindExecutable(sFile, sPath, sResult)
    Case ERROR_FILE_NOT_FOUND
      Err.Raise 53   ' file not found
    Case ERROR_PATH_NOT_FOUND
      Err.Raise 76   ' path not found
    Case ERROR_FILE_NO_ASSOCIATION
      ' returns null string
    Case Is >= ERROR_FILE_SUCCESS
      ' extract the ANSI string that contains the
      ' name of the associated executable file
      GetExecutableFile = Left$(sResult, InStr(sResult & vbNullChar, _
        vbNullChar) - 1)
  End Select
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.