Monday, June 14, 2010

VBscript for fonts installation

Script Code

VBScript
Dim oFSO, oApp, oFolderCopy, oShell
Dim strFontsPath, strScriptPath

' Create needed Objects
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Set oApp = CreateObject("Shell.Application")

' Get Path of this Script (i.E. C:\Scripts\ or \\srv\netlogon\)
strScriptPath = WScript.ScriptFullName
strScriptPath = left(strScriptPath,instrrev(strScriptPath,"\"))

' Get Path of Windows Fonts directory
strFontsPath = oShell.ExpandEnvironmentStrings("%WINDIR%") & "\Fonts"

' Get Folder Object of Fonts directory (i.E. C:\Scripts\FontsToInstall  or \\srv\netlogon\FontsToInstall)
Set oFolderCopy = oApp.Namespace(strScriptPath & "FontsToInstall")

' Check each Font if it is already installed
For Each oFont In oFolderCopy.Items
  If NOT oFSO.FileExists(strFontsPath & "\" & oFont.Name) Then
    ' Tell Explorer to copy the Font - this correctly installs it.
    oApp.Namespace(strFontsPath).CopyHere oFont
  End If
Next

' Cleanup Objects
Set oFolderCopy = Nothing
Set oApp = Nothing
Set oShell = Nothing

No comments:

Post a Comment