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 - Retrieving the executable associated to a file

Total Hit ( 2129)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
<System.Runtime.InteropServices.DllImport("shell32.dll")> Shared Function _
  FindExecutable(ByVal fileName As String, ByVal fileDir As String, _
  ByVal buffer As System.Text.StringBuilder) As Integer
End Function


' Returns the name and path of the EXEcutable file that is associated to the
' specified file.
' Returns an empty string if there is no such associated file,
' and raises an error if the file or the path hasn't been found.
'
' Example: Debug.WriteLine(GetExecutableFile("D:\temp\Db.mdb"))

Public Function GetExecutableFile(ByVal filePath As String) As String
  Const ERROR_FILE_NO_ASSOCIATION = 31&
  Const ERROR_FILE_NOT_FOUND = 2&
  Const ERROR_PATH_NOT_FOUND = 3&
  Const ERROR_FILE_SUCCESS = 32&
  Dim buffer As New System.Text.StringBuilder(260)

  ' call the FindExecutable API function and process the return value
  Select Case FindExecutable(System.IO.Path.GetFileName(filePath), _
    System.IO.Path.GetDirectoryName(filePath), buffer)
    Case ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND
      Throw New System.IO.FileNotFoundException()
    Case ERROR_FILE_NO_ASSOCIATION
      Return ""
    Case Is >= ERROR_FILE_SUCCESS
      ' extract the ANSI string that contains the name of the associated
      ' executable file
      Return buffer.ToString()
  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.