Page 1 of 1 1
Topic Options
#206795 - 2013-02-25 02:44 PM Convert from VBS not functioning as expected !
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
I have ended up shelling out to a VBscrip because I can not get the $objFont.InvokeVerb("Install") to work ?
Am i missing something or is it not possible with KIX ?

 Code:
  If exist ($TMP+$sFile)
   Dim $objShell,$objNameSpace,$objFont
   $objShell = CreateObject("Shell.Application")
   $objNameSpace = $objShell.Namespace($TMP)
   $objFont = $objNameSpace.ParseName($TMP+$sfile)
   $objFont.InvokeVerb("Install")
   ReDim $objShell,$objNameSpace,$objFont
   If Exist($DEST+$sfile)
    ? "Font "+$sfile+" Installed."
   Endif
   del $TMP+$sFile /c
  Endif


The Full VBS reads as follows:
 Code:
Option Explicit
 ' Installing multiple Fonts in Windows 7

 Dim objShell, objFSO, wshShell
 Dim strFontSourcePath, objFolder, objFont, objNameSpace, objFile, objFontsFldr, objFonts, strFonts
 Const FONTS = &H14&

 Set objShell = CreateObject("Shell.Application")
 Set wshShell = CreateObject("WScript.Shell")
 Set objFSO = createobject("Scripting.Filesystemobject")

 strFontSourcePath = "F:\CustomFonts\"

 set objFontsFldr = objShell.Namespace(FONTS)
 Set objFonts = objFontsFldr.Self
 strFonts = objFonts.Path & "\"

 If objFSO.FolderExists(strFontSourcePath) Then

 Set objNameSpace = objShell.Namespace(strFontSourcePath)
 Set objFolder = objFSO.getFolder(strFontSourcePath)

 For Each objFile In objFolder.files
  If LCase(right(objFile,4)) = ".ttf" OR LCase(right(objFile,4)) = ".otf" Then
   If objFSO.FileExists(strFonts & objFile.Name) Then
    Wscript.Echo "Font already installed: " & objFile.Name
   Else
    Set objFont = objNameSpace.ParseName(objFile.Name)
    objFont.InvokeVerb("Install")
    Wscript.Echo "Installed Font: " & objFile.Name
    Set objFont = Nothing
   End If
  End If
 Next
 Else
  Wscript.Echo "Font Source Path does not exists"
  Wscript.sleep 5000
 End If

Top
#206796 - 2013-02-25 03:17 PM Re: Convert from VBS not functioning as expected ! [Re: MACE]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Have you looked at Allen's AddFont UDF? Might need a slight upgrade for Win-7 (or to at least detect it on the Vista detection line) but should work.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#206797 - 2013-02-25 03:40 PM Re: Convert from VBS not functioning as expected ! [Re: Glenn Barnas]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
I had been using a similar method when we were an XP/2003 network and it worked fine.
For Windows 7/2008+ it caused more problems than it solved. The VBS `Install` method works fine when everything is run as Administrator but it would have been tidier to do it directly in Kix.
It makes the call but there is no apparent response as far as I can determine.

Top
#206798 - 2013-02-25 04:40 PM Re: Convert from VBS not functioning as expected ! [Re: MACE]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
I see I completely forgot about updating the Addfont UDF. It should work in its current state for Win7, but needs to be updated for Win8 and a fix for paths. Mace, I'll see what kind of results I get with the invoke method, and let you know (although it could be a day or so before I get a minute to work on this again.)
Top
#206821 - 2013-02-28 02:19 AM Re: Convert from VBS not functioning as expected ! [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
This took far to long to fix, and I found a bug in the original addfont.

Mace, your code was all but right... it was simply this line that was off...
 Code:
$objFont = $objNameSpace.ParseName($sfile)


The bug. Surprisingly, on XP the extended file properties do not work on fonts, all other files work fine. However, XP is very friendly to install fonts by simply copying the files to the font folder, and even automatically adds the registry settings.

Once you get past Vista, the original addfont requires modifying the permissions of the fonts folder and the fonts paths in the registry. Using the method Mace found, appears to avoid this.

Would someone be willing to give this a whirl and let me know what you think.

$RC=AddFont("Path\Font.ttf")
? @serror

 Code:
function AddFont($font)
  dim $title,$rc,$path,$fontname,$fontdescription,$objshell,$objfolder,$objfolderitem
  $addfont=1
  if exist($font)
    $path=left($font,instrrev($font,"\"))
    $fontname=right($font,-instrrev($font,"\"))
    if exist('%systemroot%\fonts\' + $fontname)
      exit 80
    else
      $objShell = CreateObject("Shell.Application")
      $objFolder=$objShell.NameSpace($path)
      $objFolderItem=$objFolder.ParseName($fontname)
      select
        case instr(@producttype,"Vista") or instr(@producttype,"Windows 7") or instr(@producttype,"Windows 8") or
             instr(@producttype,"Server 2008") or instr(@producttype,"Server 2012")
          $objFolderItem.InvokeVerb("Install")
          $error=@error
          if exist('%systemroot%\fonts\' + $fontname)
            $addfont=0
          else
            exit $error
          endif

        case instr(@producttype,"2000") or instr(@producttype,"Windows XP") or instr(@producttype,"2003")
          copy $font '%systemroot%\fonts\'
           if not exist('%systemroot%\fonts\' + $fontname)
            exit @error
          else
            $AddFont=0
          endif

        case 1
          exit -1 
      endselect
    endif
  else
    exit 2
  endif
endfunction

Top
#206822 - 2013-02-28 04:04 AM Re: Convert from VBS not functioning as expected ! [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, you guys saying I should update the original installfont() from 2003 too??

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84048
_________________________
!

download KiXnet

Top
#206824 - 2013-02-28 11:58 AM Re: Convert from VBS not functioning as expected ! [Re: Lonkero]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
FYI:
Using the VBS with the invoke method works fine on my XP SP3 test machines as well as the newer platforms so you don't really need to be testing for which platform within the UDF.
If someone has got W2K systems still in use they might as well use the old method.

If you think the above was hard, You should see what I needed to do to 'Un-Install fonts'!
With the issues I was having which caused the need for the scripts in the first place I had copies of Windows 7 with numerous copies of the same font installed as the 2K3 method royaly broke Windows and users had to keep going to the font source and manually re-installing.

NB: When you read the extended attributes of a file in XP it gives totally different lines of output than in other OS's, became unneccesarily complicated so in the end it was a matter of parsing the registry and extracting the font file names to compare against the baseline ...Takes a bit longer but ALL file versions and the registry could be pruned. Even then Windows 7 in my case would randomly fail to delete properly some of the registry entries...and even re-booted on occasion, NOT FUN

Top
#206825 - 2013-02-28 02:29 PM Re: Convert from VBS not functioning as expected ! [Re: MACE]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Just for KiX ;-) I've translated the VBS, didn't test it though:
 Code:
$=SetOption('Explicit','On')
; Installing multiple Fonts in Windows 7

Dim $objShell, $objFSO
Dim $strFontSourcePath, $objFolder, $objFont, $objNameSpace, $objFile, $objFontsFldr, $objFonts, $strFonts
$FONTS = &14&

$objShell = CreateObject("Shell.Application")
$objFSO = CreateObject("Scripting.FileSystemObject")

$strFontSourcePath = "F:\CustomFonts\"

$objFontsFldr = $objShell.Namespace($FONTS)
$objFonts = $objFontsFldr.Self
$strFonts = $objFonts.Path + "\"

If Exist($strFontSourcePath)
  $objNameSpace = $objShell.Namespace($strFontSourcePath)
  $objFolder = $objFSO.GetFolder($strFontSourcePath)
  For Each $objFile In $objFolder.files
    If LCase(right($objFile,4)) = ".ttf" OR LCase(right($objFile,4)) = ".otf"
      If $objFSO.FileExists($strFonts+$objFile.Name)
        ? "Font already installed: "+$objFile.Name
      Else
        $objFont = $objNameSpace.ParseName($objFile.Name)
        $objFont.InvokeVerb("Install")
        ? "Installed Font: "+$objFile.Name
        $objFont = ""
      EndIf
    EndIf
  Next
Else
  ? "Font Source Path does not exists"
  sleep 5000
EndIf

Top
#206826 - 2013-02-28 02:43 PM Re: Convert from VBS not functioning as expected ! [Re: Arend_]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
 Quote:
Using the VBS with the invoke method works fine on my XP SP3 test machines as well


Interesting. I didn't try it because when you right click on the font in XP, there was no option to install, like there is in the newer OSs.

Top
#206828 - 2013-02-28 04:08 PM Re: Convert from VBS not functioning as expected ! [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Mace, would you mind testing the invoke method again on XP (SP3)... it didn't work for me.
Top
#206857 - 2013-03-04 10:06 AM Re: Convert from VBS not functioning as expected ! [Re: Allen]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
OK Allen You are technically correct. I built myself a vanilla XP VM and it most certainly wont run the .install method.
As to our two remaining XP Test stations, without spending lots of unavailable time it is unclear why they did not object other than months of adultiration with all sorts of other libraries. Anyway you can rest assured your method is correct and XP can use the File+Reg method as detailed.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.059 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org