-
Notifications
You must be signed in to change notification settings - Fork 128
/
InstallFonts.vbs
135 lines (104 loc) · 3.6 KB
/
InstallFonts.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'*******************************************************************************
' Author: Mick Pletcher
' Date: 17 October 2012
' Modified:
'
' Description: This will install all fonts residing in the same folder as this
' script.
' 1) Define the relative installation path
' 2) Create the Log Folder
' 3) Read list of Fonts into Array
' 4) Install Fonts
' 5) Cleanup Global Memory
'*******************************************************************************
Option Explicit
REM Define Constants
CONST TempFolder = "c:\temp\"
CONST LogFolderName = "Fonts"
REM Define Global Variables
DIM Count : Count = 1
DIM LogFolder : LogFolder = TempFolder & LogFolderName & "\"
DIM RelativePath : Set RelativePath = Nothing
ReDIM arrFiles(1)
REM Define the relative installation path
DefineRelativePath()
REM Create the Log Folder
CreateLogFolder()
REM Read list of Fonts into Array
ReadFonts()
REM Install Fonts
InstallFonts()
REM Cleanup Global Memory
GlobalMemoryCleanup()
'*******************************************************************************
'*******************************************************************************
Sub DefineRelativePath()
REM Get File Name with full relative path
RelativePath = WScript.ScriptFullName
REM Remove file name, leaving relative path only
RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))
End Sub
'*******************************************************************************
Sub CreateLogFolder()
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
If NOT FSO.FolderExists(TempFolder) then
FSO.CreateFolder(TempFolder)
End If
If NOT FSO.FolderExists(LogFolder) then
FSO.CreateFolder(LogFolder)
End If
REM Cleanup Local Variables
Set FSO = Nothing
End Sub
'*******************************************************************************
Sub ReadFonts()
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
REM Define Local Variables
DIM Folder : Set Folder = FSO.GetFolder(RelativePath)
DIM Files : Set files = Folder.Files
DIM File : Set File = Nothing
For each File in Files
If NOT Left(File.Name,Len(File.Name)-4) = "Install" then
arrFiles(Count) = File.Name
Count = Count + 1
ReDim Preserve arrFiles(Count)
End If
Next
Count = Count - 1
REM Cleanup Local Memory
Set File = Nothing
Set Files = Nothing
Set Folder = Nothing
Set FSO = Nothing
End Sub
'*******************************************************************************
Sub InstallFonts()
REM Define Local Constants
Const FONTS = &H14&
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
DIM i : Set i = Nothing
DIM oShell : SET oShell = CreateObject("Shell.Application")
DIM oFolder : Set oFolder = oShell.Namespace(FONTS)
DIM WshShell : Set WshShell = WScript.CreateObject("Wscript.Shell")
For i = 1 to Count
If NOT FSO.FileExists("c:\windows\Fonts\" & arrFiles(i)) then
oFolder.CopyHere RelativePath & arrFiles(i), 16
End If
Next
REM Cleanup Local Variables
Set FSO = Nothing
Set i = Nothing
Set oFolder = Nothing
Set oShell = Nothing
Set WshShell = Nothing
End Sub
'*******************************************************************************
Sub GlobalMemoryCleanup()
Set Count = Nothing
Set LogFolder = Nothing
Set RelativePath = Nothing
Erase arrFiles
End Sub