VBS Font Install...

Discussion in 'Scripting' started by KNARZ, May 28, 2014.

  1. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    865
    447
    30
    #1 KNARZ, May 28, 2014
    Last edited by a moderator: Apr 20, 2017
    I'm good at batch but I suck on VBS Badly.
    Can someone help me, please?!

    I want to point as an argument to a directory with fonts
    (Cmd should look like this: xxx.vbs "X:\anything\ye ah\fonts")
    the script should look if the font is already installed and skip it otherwise install.
    If the argument is missing the script should exit or give out some error-message

    the whole point is to keep the script flexible and language neutral. - the sourcepath/argument can contain spaces.

    the commented ' lines prevent the script from running. therefore i comment them it in the first place.

    my messy work so far:
    Code:
    Dim objShell, objFSO
    Dim strFontDirectoryPath, strFontSourcePath
    Dim objFolder, objFont, objNameSpace, objFile
    
    Set objArgs = WScript.Arguments
    'if objArgs.Count = 0 then WScript.Quit
    
    Set objShell = WScript.CreateObject("Wscript.Shell")
    'Set objShell = CreateObject("Shell.Application")
    Set objFSO = createobject("Scripting.Filesystemobject")
    
    strFontDirectoryPath = objShell.SpecialFolders.Item("Fonts")
    'strFontSourcePath = (WScript.Arguments.Item(0))
    
    Wscript.Echo "Font Directory: " & strFontDirectoryPath
    Wscript.Echo "Font Source: " & ItemFolder
    
    
    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
                Set objFont = objNameSpace.ParseName(objFile.Name)
                If objFSO.FileExists(strFontDirectoryPath & objFile.Name) = False Then
                    objFont.InvokeVerb("Install")
                End If
                Wscript.Echo "Installed Font: " & objFont
                Set objFont = Nothing
            End If
        Next
    Wscript.Echo "Font Source Path does not exists"
    End If
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    865
    447
    30
    thanks... I will test it later but I would also appreciate it if someone gets the vbs working.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    865
    447
    30
    I would donate 10-15$ with paypal if i get this vb script working and from my tasklist.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...