[API]
RegCloseKey

[INCLUDE]
RegDeleteKey
RegDeleteValue
RegOpenKeyEx
RegEnumKey
RegQueryValueEx_String
RegSetValueEx_String

[CODE]
Public Function RegisterFileTypes_RemoveRegistered(ByVal FileType As String, ByVal ProgramCaption As String, Optional ByVal DefaultActionBackupCaption As String) As Boolean
  'returns 0 if found itself's deficon
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xBool1 As Boolean
  Dim xChar1 As String
  Dim xChar3 As String
  
  
  FileType = LCase(FileType)
  If RegOpenKeyEx(&H80000000, "." + FileType, 1&, xLong1) Then
    xBool1 = RegQueryValueEx_String(xLong1, "", xChar1)
    Call RegCloseKey(xLong1)
    End If
  
  If xBool1 Then
    '1/2?
    If RegOpenKeyEx(&H80000000, "", 0&, xLong1) Then
      Call RegDeleteKey(xLong1, xChar1 + "\Shell\" + ProgramCaption)
      If RegOpenKeyEx(&H80000000, xChar1 + "\Shell", 8&, xLong2) Then
        xLong3 = CLng(RegEnumKey(xLong2, 0&, xChar3))   '= 259& Then
        Call RegCloseKey(xLong2)
        If xLong3 = 0& Then
          If Not Len(xChar1) = 0& Then
            If Asc(xChar1) > 34& Or Asc(xChar1) = 33& Then
              Call RegDeleteKey(xLong1, xChar1 + "\Shell")
              End If
            End If
          End If
        End If
      Call RegCloseKey(xLong1)
      End If
    
    If Not Len(DefaultActionBackupCaption) = 0& Then
      If RegOpenKeyEx(&H80000000, xChar1 + "\Shell", 3&, xLong1) Then
        If RegQueryValueEx_String(xLong1, DefaultActionBackupCaption, xChar3) Then
          Call RegSetValueEx_String(xLong1, "", xChar3)
          Call RegDeleteValue(xLong1, DefaultActionBackupCaption)
          End If
        End If
      End If
    
    If RegOpenKeyEx(&H80000000, xChar1 + "\DefaultIcon", 1&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar3) Then
        xLong3 = 0
        Do
          xLong2 = InStr(xLong3 + 1, xChar3, ",")
          If xLong2 = 0 Then Exit Do
          xLong3 = xLong2
          Loop
        If Not xLong3 = 0 Then
          xChar3 = Left(xChar3, xLong3 - 1)
          End If
        If LCase(xChar3) = LCase(AppBase) Then
          xBool1 = False
          End If
        End If
      Call RegCloseKey(xLong1)
      End If
    If Not xBool1 Then
      If RegOpenKeyEx(&H80000000, "", 2&, xLong1) Then
        Call RegDeleteKey(xLong1, xChar1 + "\DefaultIcon")
        RegisterFileTypes_RemoveRegistered = True
        Call RegCloseKey(xLong1)
        End If
      End If
    If RegOpenKeyEx(&H80000000, xChar1 + "\Shell", 3&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar3) Then
        If xChar3 = ProgramCaption Then
          Call RegDeleteValue(xLong1, "")
          End If
        End If
      Call RegCloseKey(xLong1)
      End If
    End If
  End Function
