Delete an ODBC entry: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
m (Added category links.)
Line 69: Line 69:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
[[{{ns:14}}:Database Functions]]

Revision as of 20:58, 30 April 2005

Author: preisl (talk, contrib)


The Function

;
; Delete an existing ODBC Entry
;
; Requires: ODBCEntryExists
;    Input: Name of the ODBC entry
;   Output: None
;
; Usage:
;
;    Push "ODBCTEST"
;    Call DeleteODBCEntry
;    MessageBox MB_OK|MB_ICONINFORMATION "ODBC entry 'ODBCTEST' deleted"
;
 
!macro DeleteODBCEntryMacro PREFIX
 
  ; Clear all errors first
  ClearErrors
  ; Pop the name of the ODBC entry from the stack
  Exch $R0
  Push $R1
 
  IfErrors InvalidParameter DeleteEntry
  InvalidParameter:
    MessageBox MB_OK|MB_ICONEXCLAMATION "DeleteODBCEntry: Please push the name of the ODBC entry first."
    Goto Done
 
  DeleteEntry:
 
    ; Check whether the ODBC entry already exists
    Push $R0
    Call ${PREFIX}ODBCEntryExists
    Pop $R1
    StrCmp $R1 "FALSE" Done
 
    ; Delete the registry keys
    ClearErrors
    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R0"
    IfErrors ErrorKey DeleteValue
    ErrorKey:
      MessageBox MB_OK|MB_ICONEXCLAMATION "Could not delete the registry key:$\r$\rHKLM - SOFTWARE\ODBC\ODBC.INI\$R0$\r$\rPlease delete this registry key manually !"
    DeleteValue:
    ClearErrors
    DeleteRegValue HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" "$R0"
    IfErrors ErrorValue Done
    ErrorValue:
      MessageBox MB_OK|MB_ICONEXCLAMATION "Could not delete the registry value:$\r$\rHKLM - SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\$R0$\r$\rPlease delete this registry value manually !"
 
  Done:
 
  ; Restore R0-R1
  Pop $R1
  Pop $R0
 
!macroend
 
Function DeleteODBCEntry
  !insertmacro DeleteODBCEntryMacro ""
FunctionEnd
 
Function un.DeleteODBCEntry
  !insertmacro DeleteODBCEntryMacro "un."
FunctionEnd