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

CreateFileAssociation - Creating a new file association

Total Hit ( 4480)

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 Sub _
  SHChangeNotify(ByVal wEventId As Integer, ByVal uFlags As Integer, _
  ByVal dwItem1 As Integer, ByVal dwItem2 As Integer)
End Sub


' Create the new file association
'
' Extension is the extension to be registered (eg ".cad"
' ClassName is the name of the associated class (eg "CADDoc")
' Description is the textual description (eg "CAD Document"
' ExeProgram is the app that manages that extension (eg "c:\Cad\MyCad.exe")

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

  ' ensure that there is a leading dot
  If extension.Substring(0, 1) <> "." Then
    extension = "." & extension
  End If

  Dim key1, key2, key3 As Microsoft.Win32.RegistryKey
  Try
    ' create a value for this key that contains the classname
    key1 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension)
    key1.SetValue("", className)
    ' create a new key for the Class name
    key2 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className)
    key2.SetValue("", description)
    ' associate the program to open the files with this extension
    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

  ' notify Windows that file associations have changed
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0)
  Return True
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.