[API]
RegCloseKey

[INCLUDE]
RegCreateKeyEx
RegDeleteValue
RegOpenKeyEx
RegQueryValueEx_String
RegSetValueEx_String

[CODE]
Public Function RegisterFileTypes_SetRegistered(ByVal FileType As String, ByVal GlobalFileType As String, ByVal ProgramCaption As String, ByVal OpeningCaption As String, Optional ByVal Description As String = vbNullChar, Optional ByVal Parameters As String = "", Optional ByVal IconIndex As Long = -1&, Optional ByVal AsDefaultRegistered As Boolean = False, Optional ByVal PassiveRegistration As Boolean = True, Optional ByVal DefaultActionBackupCaption As String) As Boolean
  Dim xLong1 As Long
  Dim xBool1 As Boolean
  Dim xChar1 As String
  Dim xChar2 As String
  
  FileType = LCase(FileType)
  If PassiveRegistration Then
    If RegOpenKeyEx(&H80000000, "." + FileType, 1&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar1) Then
        GlobalFileType = xChar1
        xBool1 = True
        End If
      Call RegCloseKey(xLong1)
      End If
    End If
  
  If Not xBool1 Then
    If RegCreateKeyEx(&H80000000, "." + FileType, xLong1) Then
      Call RegSetValueEx_String(xLong1, "", GlobalFileType)
      Call RegCloseKey(xLong1)
      End If
    End If
  
  If (Not xBool1 Or AsDefaultRegistered) And Not Description = Chr(0) Then
    If RegCreateKeyEx(&H80000000, GlobalFileType, xLong1) Then
      Call RegSetValueEx_String(xLong1, "", Description)
  '    RegisterFileTypes_SetRegistered = True
      Call RegCloseKey(xLong1)
      End If
    End If
  
  xChar2 = LCase(AppBase)
  If Not AsDefaultRegistered Then
    '1/2?
    If RegOpenKeyEx(&H80000000, GlobalFileType + "\DefaultIcon", 0&, xLong1) Then
      Call RegCloseKey(xLong1)
      xBool1 = False
      Else
      xBool1 = True
      End If
    End If
  If (AsDefaultRegistered Or xBool1 And Not IconIndex = -1&) Then
    If RegCreateKeyEx(&H80000000, GlobalFileType + "\DefaultIcon", xLong1) Then
      xChar1 = xChar2 & "," & CStr(IconIndex)
      Call RegSetValueEx_String(xLong1, "", xChar1)
      RegisterFileTypes_SetRegistered = True
      Call RegCloseKey(xLong1)
      End If
    End If
  
  If AsDefaultRegistered Then
    If Not Len(DefaultActionBackupCaption) = 0& Then
      If RegOpenKeyEx(&H80000000, GlobalFileType + "\Shell", 3&, xLong1) Then
        If Not RegQueryValueEx_String(xLong1, DefaultActionBackupCaption, xChar1) Then
          If RegQueryValueEx_String(xLong1, "", xChar1) Then
            Call RegSetValueEx_String(xLong1, DefaultActionBackupCaption, xChar1)
            End If
          End If
        End If
      End If
    If RegCreateKeyEx(&H80000000, GlobalFileType + "\Shell", xLong1) Then
      Call RegSetValueEx_String(xLong1, "", ProgramCaption)
      Call RegCloseKey(xLong1)
      End If
    ElseIf Not Len(DefaultActionBackupCaption) = 0& Then
    If RegOpenKeyEx(&H80000000, GlobalFileType + "\Shell", 3&, xLong1) Then
      If RegQueryValueEx_String(xLong1, DefaultActionBackupCaption, xChar1) Then
        Call RegSetValueEx_String(xLong1, "", xChar1)
        Call RegDeleteValue(xLong1, DefaultActionBackupCaption)
        End If
      End If
    End If
  
  If RegCreateKeyEx(&H80000000, GlobalFileType + "\Shell\" + ProgramCaption, xLong1) Then
    Call RegSetValueEx_String(xLong1, "", OpeningCaption)
    Call RegCloseKey(xLong1)
    End If
  If RegCreateKeyEx(&H80000000, GlobalFileType + "\Shell\" + ProgramCaption + "\Command", xLong1) Then
    xChar1 = Chr(34) + xChar2 + Chr(34) + " " + Chr(34) + "%1" + Chr(34)
    If Not Parameters = "" Then
      xChar1 = xChar1 + " " + Parameters
      End If
    Call RegSetValueEx_String(xLong1, "", xChar1)
    Call RegCloseKey(xLong1)
    End If
  End Function
