File Associations : Registry « Windows System « VB.Net






File Associations

  
Imports Microsoft.Win32

Public Class MainClass
    Public Function GetAssociatedProgram(ByVal FileExtension As String) As String
        Dim objExtReg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
        Dim objAppReg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
        Dim strExtValue As String
        Try
            If FileExtension.Substring(0, 1) <> "." Then FileExtension = "." & FileExtension
            objExtReg = objExtReg.OpenSubKey(FileExtension.Trim)
            strExtValue = objExtReg.GetValue("")
            objAppReg = objAppReg.OpenSubKey(strExtValue & "\shell\open\command")
            Dim SplitArray() As String
            SplitArray = Split(objAppReg.GetValue(Nothing), """")
            If SplitArray(0).Trim.Length > 0 Then
                Return SplitArray(0).Replace("%1", "")
            Else
                Return SplitArray(1).Replace("%1", "")
            End If
        Catch
            Return ""
        End Try
    End Function

End Class

   
    
  








Related examples in the same category

1.Read and write with Registry
2.Saving to the Registry