Código vb:
Ver originalPublic Class Example
Public Sub RegisterType()
Dim fileReg As New FileTypeRegistrar
With fileReg
.FullPath = Path_To_Executable
.FileExtension = Extension_To_Register
.ContentType = "application/" & Your_Description
.IconIndex = Icon_Index_In_Application
.IconPath = Path_To_Executable
.ProperName = Name_Of_Executable
.CreateType()
End With
End Sub
End Class
Public Class FileTypeRegistrar
#Region "Properties & Property Variables"
Private _ProperName As String
Public Property ProperName() As String
Get
Return _ProperName
End Get
Set(ByVal Value As String)
_ProperName = Value
End Set
End Property
Private _ContentType As String
Public Property ContentType() As String
Get
Return _ContentType
End Get
Set(ByVal Value As String)
_ContentType = Value
End Set
End Property
Private _FullPath As String
Public Property FullPath() As String
Get
Return _FullPath
End Get
Set(ByVal Value As String)
_FullPath = Value
End Set
End Property
Private _FileExtension As String
Public Property FileExtension() As String
Get
Return _FileExtension
End Get
Set(ByVal Value As String)
_FileExtension = Value.Replace(".", "")
End Set
End Property
Private _IconPath As String
Public Property IconPath() As String
Get
Return _IconPath
End Get
Set(ByVal Value As String)
_IconPath = Value
End Set
End Property
Private _IconIndex As Integer
Public Property IconIndex() As Integer
Get
Return _IconIndex
End Get
Set(ByVal Value As Integer)
_IconIndex = Value
End Set
End Property
#End Region
#Region "Public Methods"
Public Sub CreateType()
Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
Dim Ext As String = "." & FileExtension.ToLower
Dim extKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(Ext)
extKey.SetValue("", fileName)
extKey.SetValue("Content Type", ContentType)
extKey.Close()
Dim mainKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(fileName)
Dim defIconKey As RegistryKey = mainKey.CreateSubKey("DefaultIcon")
defIconKey.SetValue("", IconPath & ", " & IconIndex)
defIconKey.Close()
Dim shellKey As RegistryKey = mainKey.CreateSubKey("shell")
Dim OpenKey As RegistryKey = shellKey.CreateSubKey("Open")
Dim cmdKey As RegistryKey = OpenKey.CreateSubKey("command")
cmdKey.SetValue("", """" & FullPath & " %1""")
cmdKey.Close()
OpenKey.Close()
shellKey.Close()
mainKey.Close()
End Sub
Public Sub DeleteType()
Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
Dim Ext As String = "." & FileExtension.ToLower
Registry.ClassesRoot.DeleteSubKey(Ext)
Registry.ClassesRoot.DeleteSubKey(fileName)
End Sub
#End Region
End Class
Fuente:
http://bytes.com/topic/net/answers/5...am#post2040365