Results 1 to 3 of 3

Thread: Find executable associated with a particular file extension?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011

    Question Find executable associated with a particular file extension?

    I am converting my project from VB6 to in Visual Studio 2013

    I need to find out if my user already has an executable associated with a particular file extension (eg does the user already have an application installed that deals with files such as "thisfile.abcd")

    Currently, I do this using APIs but one of the "selling points" of is that you don't need to use APIs any more. So, how do I do this without APIs?

    Or, if that is not possible, the simplest way

  2. #2
    Lively Member ShadowTzu's Avatar
    Join Date
    Oct 2014

    Re: Find executable associated with a particular file extension?

     Private Function GetFileAssociation(ext As String) As String
    Dim RegKey As Microsoft.Win32.RegistryKey
    RegKey = My.Computer.Registry.ClassesRoot.OpenSubKey(ext, False)
    If RegKey Is Nothing Then Return "-1"
    RegKey = My.Computer.Registry.ClassesRoot.OpenSubKey(RegKey.GetValue(Nothing).ToString & "\shell\open\command")
    Dim result As String = RegKey.GetValue(Nothing).ToString
    Dim exefile As String = Split(result, ".exe")(0) & ".exe"
    Return exefile
    End Function
    Dim ext As String = GetFileAssociation(".coucou")
    If ext = "-1" Then
        MsgBox("ext not found")
    End If
    Last edited by ShadowTzu; Nov 24th, 2014 at 08:02 AM.

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Manchester uk

    Re: Find executable associated with a particular file extension?

    Well file association are just stored in the registry, i assume your VB6 code just used API's to read from the registry!

    Looking in my registry now under HKEY_CLASSES_ROOT i can see for instance ".dot" and the default value is "Word.Template.8", you will also see a Content Type which will hold details on the program that is associated with the file extension. e. g. - "application/msword"

    There is a direct framework class to work with the registry, you just need to import - Microsoft.Win32 to you class / form.

    This may also help with the details of working with the registry.

    Edit - Looks like you now have pretty much the exact code too now from ShadowTzu
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width