;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       AddFont() 
;; 
;;ACTION         Adds a font to the local font database 
;; 
;;AUTHOR         Allen Powell 
;; 
;;VERSION        1.0  - 2009/01/07 
;; 
;;HISTORY        1.0  - 2009/01/07 - Initial Release 
;; 
;;SYNTAX         AddFont(FontFilespec [, Force]) 
;; 
;;PARAMETERS     FontFilespec - REQUIRED - full pathspec to font file 
;; 
;;		 Force - OPTIONAL 
;;               - Flag to overwrite existing font file 
;; 
;;REMARKS        Updated by gbarnas for positive return logic, ITCG coding standards 
;; 
;;RETURNS        1 if success, 0 if failure (Check @ERROR for reason) 
;; 
;;DEPENDENCIES   Admin or as least change permissions to the Fonts directory 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       If AddFont(@SCRIPTDIR + '\BNHRDFAN.TTF') 
;;		   'Installed successfully!' ? 
;;		 Else 
;;		   @SERROR ?  
;;		 EndIf 
; 
Function AddFont($_Font, OPTIONAL $_Force)
 
  Dim $_Title					;  
  Dim $_Rc					;  
  Dim $_Path					;  
  Dim $_FontName				;  
  Dim $_FontDescription				;  
  Dim $_objShell, $_objFolder, $_objFolderItem	;  
 
  $AddFont = 0					; Assume failure 
 
  if Exist($_Font)				; proceed if source font exists 
    $_Path = Left($_Font, InStrRev($_Font, '\'))
    $_FontName = SubStr($_Font, InStrRev($_Font, '\') + 1)
    $_objShell = CreateObject('Shell.Application')
 
    If @ERROR
      Exit @ERROR				; exit FAIL TO INSTANTIATE COM 
    EndIf
    Select
     Case InStr(@PRODUCTTYPE, '2000')
      $_Title = 11
     Case InStr(@PRODUCTTYPE, 'XP') Or InStr(@PRODUCTTYPE, '2003')
      $_Title = 10
     Case InStr(@PRODUCTTYPE, 'Vista')
      $_Title = 21
     Case 1
      Exit 87					; exit INVALID PARAMETER 
    EndSelect
 
    $_objFolder = $_objShell.NameSpace($_Path)
    If Not $_objFolder				; possible relative or invalid path 
      Exit 87
    Endif
 
    $_objFolderItem = $_objFolder.ParseName($_FontName)
    $_FontDescription = $_objFolder.GetDetailsOf($_objFolderItem, $_Title)
    If InStr($_FontName, 'ttf') Or InStr($_FontName, 'ttc')
      $_FontDescription = $_FontDescription + ' (TrueType)'
    EndIf
 
    If CompareFileTimes($_Font, '%WINDIR%\fonts\' + $_FontName) or $_Force
      Copy $_Font '%WINDIR%\fonts\'
      If @ERROR
        Exit @ERROR				; exit FAILED TO COPY 
      EndIf
 
      ; Update the registered fonts database 
      $_Rc = WriteValue('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', $_FontDescription, $_FontName, 'REG_SZ')
      If @ERROR
        Exit @ERROR				; exit FAILED TO WRITE REGISTRY 
      EndIf
 
      $AddFont = 1				; declare success 
    Else
      Exit 80					; exit FILE EXISTS 
    EndIf
  Else
    Exit 2					; exit NOT FOUND 
  EndIf
 
  Exit 0					; exit success 
 
EndFunction