<System.Runtime.InteropServices.DllImport("shell32.dll")> Shared Sub _ SHChangeNotify(ByVal wEventId As Integer, ByVal uFlags As Integer, _ ByVal dwItem1 As Integer, ByVal dwItem2 As Integer) End Sub
Function CreateFileAssociation(ByVal extension As String, _ ByVal className As String, ByVal description As String, _ ByVal exeProgram As String) As Boolean Const SHCNE_ASSOCCHANGED = &H8000000 Const SHCNF_IDLIST = 0
If extension.Substring(0, 1) <> "." Then extension = "." & extension End If
Dim key1, key2, key3 As Microsoft.Win32.RegistryKey Try key1 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension) key1.SetValue("", className) key2 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className) key2.SetValue("", description) key3 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className & _ "\Shell\Open\Command") key3.SetValue("", exeProgram & " ""%1""") Catch e As Exception Return False Finally If Not key1 Is Nothing Then key1.Close() If Not key2 Is Nothing Then key2.Close() If Not key3 Is Nothing Then key3.Close() End Try
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0) Return True End Function |