by BrijMohan k (1 Submission)
Category: Registry
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 6th February 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Create File association in 10 lines of code (VerySimple)
API Declarations
In a form place the following code
associate ".jpg", "JPGFile", "C:\Program Files\Accessories\MSPAINT.EXE"
Unload Me
End Sub
Public Sub associate(EXT As String, FileType As String, FileName As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject("wscript.shell")
b.regwrite "HKCR\" & EXT & "\", FileType
b.regwrite "HKCR\" & FileType & "\", "MY file"
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", FileName
b.regwrite "HKCR\" & FileType & "\shell\open\command\", FileName & " %L"
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName
End Sub