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 - Associate a file extension to a program
[ All Languages » VB »  Windows]

Total Hit ( 3487)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Sub SHChangeNotify Lib "shell32.dll" (ByVal wEventId As Long, _
  ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long)
Const SHCNE_ASSOCCHANGED = &H8000000
Const SHCNF_IDLIST = 0

' 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")
'
' NOTE: requires CreateRegistryKey and SetRegistryValue functions

Sub CreateFileAssociation(ByVal Extension As String, ByVal ClassName As String, _
  ByVal Description As String, ByVal ExeProgram As String)
  Const HKEY_CLASSES_ROOT = &H80000000
  
  ' ensure that there is a leading dot
  If Left(Extension, 1) <> "." Then
    Extension = "." & Extension
  End If
 
  ' create a new registry key under HKEY_CLASSES_ROOT
  CreateRegistryKey HKEY_CLASSES_ROOT, Extension
  ' create a value for this key that contains the classname
  SetRegistryValue HKEY_CLASSES_ROOT, Extension, "", ClassName
  ' create a new key for the Class name
  CreateRegistryKey HKEY_CLASSES_ROOT, ClassName & "\Shell\Open\Command"
  ' set its value to the command line
  SetRegistryValue HKEY_CLASSES_ROOT, ClassName & "\Shell\Open\Command", "", _
    ExeProgram & " ""%1"""

  ' notify Windows that file associations have changed
  SHChangeNotify SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0
End Sub


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.