forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallCCTK_old.vbs
472 lines (384 loc) · 14.9 KB
/
InstallCCTK_old.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
'*******************************************************************************
' Program: Install.vbs
' Author: Mick Pletcher
' Date:
' Modified:
'
' Program:
' Version:
' Description: This will do the following to the MDT/SCCM generated WIM files:
' inject the Dell CCTK, inject the HAPI drivers, and modify the
' unattend.xml file.
' Requirements: Microsoft WAIK, location for the locally stored WinPE files
' (WinPEDIR Global Variable), MDT Server (I have 2 servers
' MDT01 and MDT02), designation of architecture, and Dell CCTK.
' NOTE: This script has been created to automate the update process
' on a Windows 7 64-bit PC, therefor the directory locations of
' the CCTK files will differ for an x86 machine.
'*******************************************************************************
Option Explicit
REM Define Constants
CONST TempFolder = "c:\temp\"
CONST LogFolderName = "CCTK"
CONST MDT01 = "MDT01"
CONST MDT02 = "MDT02"
CONST WinPEDIR = "c:\winpe\"
CONST x64 = "x64"
CONST x86 = "x86"
REM Define Global Variables
DIM LogFolder : LogFolder = TempFolder & LogFolderName & "\"
DIM RelativePath : Set RelativePath = Nothing
DefineRelativePath()
REM Refresh Local WIM Files from MDT Servers
DeleteLocalWIMFiles()
CopyWIMFiles( MDT01 )
RenameWIMFiles( MDT01 )
CopyWIMFiles( MDT02 )
RenameWIMFiles( MDT02 )
REM Process Local x86 file for MDT01
MountWIM MDT01,x86
AddWMI(x86)
CopyHAPIFiles( x86 )
CopyCCTKFiles( x86 )
EditUnattend( x86 )
DismountWIM()
REM Process Local x64 File for MDT01
MountWIM MDT01,x64
AddWMI(x64)
CopyHAPIFiles( x64 )
CopyCCTKFiles( x64 )
EditUnattend( x64 )
DismountWIM()
REM Process Local x86 File for MDT02
MountWIM MDT02,x86
AddWMI(x86)
CopyHAPIFiles( x86 )
CopyCCTKFiles( x86 )
EditUnattend( x86 )
DismountWIM()
REM Process Local x64 File for MDT02
MountWIM MDT02,x64
AddWMI(x64)
CopyHAPIFiles( x64 )
CopyCCTKFiles( x64 )
EditUnattend( x64 )
DismountWIM()
Complete()
GlobalVariableCleanup()
'*******************************************************************************
'*******************************************************************************
Sub DefineRelativePath()
REM Define Local Objects
DIM oShell : Set oShell = CreateObject("WScript.Shell")
REM Get File Name with full relative path
RelativePath = WScript.ScriptFullName
REM Remove file name, leaving relative path only
RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))
REM Cleanup Local Variables
Set oShell = Nothing
End Sub
'*******************************************************************************
Sub DeleteLocalWIMFiles()
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM Parameters : Parameters = "/F /Q"
DIM sCMD_1 : sCMD_1 = "%COMSPEC% /c del " & RelativePath & "*MDT01.wim"
DIM sCMD_2 : sCMD_2 = "%COMSPEC% /c del " & RelativePath & "*MDT02.wim"
DIM sCMD_3 : sCMD_3 = "%COMSPEC% /c del " & RelativePath & "generic*.wim"
oShell.Run sCMD_1 & Parameters, 1, True
oShell.Run sCMD_2 & Parameters, 1, True
oShell.Run sCMD_3 & Parameters, 1, True
REM Cleanup Local Variables
Set sCMD_1 = Nothing
Set sCMD_2 = Nothing
Set sCMD_3 = Nothing
Set FSO = Nothing
Set oShell = Nothing
Set Parameters = Nothing
End Sub
'*******************************************************************************
Function CopyWIMFiles(Server)
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM Source : Source = "\\" & Server & "\DeploymentShare\Boot"
DIM Destination : Destination = "c:\winpe"
DIM Parameters : Parameters = "*.wim /eta /r:1 /w:0"
DIM Command01 : Command01 = "robocopy" & Chr(32) & Source & Chr(32) & Destination & Chr(32) & Parameters
oShell.Run Command01, 1, True
REM Cleanup Local Variables
Set Command01 = Nothing
Set Destination = Nothing
Set oShell = Nothing
Set Parameters = Nothing
Set Source = Nothing
End Function
'*******************************************************************************
Function RenameWIMFiles(Server)
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
REM Define Local Variables
DIM Source_x86 : Source_x86 = RelativePath & "LiteTouchPE_x86.wim"
DIM Source_x64 : Source_x64 = RelativePath & "LiteTouchPE_x64.wim"
DIM Dest_x86 : Dest_x86 = RelativePath & "LiteTouchPE_x86_" & Server & ".wim"
DIM Dest_x64 : Dest_x64 = RelativePath & "LiteTouchPE_x64_" & Server & ".wim"
If FSO.FileExists(Source_x86) then
If NOT FSO.FileExists(Dest_x86) then
FSO.MoveFile Source_x86, Dest_x86
End If
End If
If FSO.FileExists(Source_x64) then
If NOT FSO.FileExists(Dest_x64) then
FSO.MoveFile Source_x64, Dest_x64
End If
End If
REM Cleanup Local Variables
Set Dest_x86 = Nothing
Set Dest_x64 = Nothing
Set FSO = Nothing
Set Source_x86 = Nothing
Set Source_x64 = Nothing
End Function
'*******************************************************************************
Function MountWIM(Server,Architecture)
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM MountDIR : MountDIR = RelativePath & "Mount"
DIM WIMFile : WIMFile = RelativePath & "LiteTouchPE_" & Architecture & "_" & Server & ".wim"
DIM Command01 : Command01 = "DISM /Mount-Wim /WIMFile:" & WIMFile & Chr(32) & "/Index:1 /MountDIR:" & MountDIR
oShell.Run Command01, 1, True
REM Cleanup Local Variables
Set Command01 = Nothing
Set MountDIR = Nothing
Set oShell = Nothing
Set WIMFile = Nothing
End Function
'*******************************************************************************
Sub AddWMI(Architecture)
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM Image : Image = "/Image:" & RelativePath & "Mount"
DIM AddPackage : AddPackage = "/Add-Package"
DIM PackagePath : Set PackagePath = Nothing
DIM PackagePath_x86 : PackagePath_x86 = "/PackagePath:" & Chr(34) &_
"C:\Program Files\Windows AIK\Tools\PETools\x86\WinPE_FPs\winpe-wmi.cab" & Chr(34)
DIM PackagePath_x64 : PackagePath_x64 = "/PackagePath:" & Chr(34) &_
"C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs\winpe-wmi.cab" & Chr(34)
DIM Command01 : Set Command01 = Nothing
If Architecture = "x86" Then
PackagePath = PackagePath_x86
Else
PackagePath = PackagePath_x64
End If
Command01 = "DISM" & Chr(32) & Image & Chr(32) & AddPackage & Chr(32) & PackagePath
oShell.Run Command01, 1, True
REM Cleanup Local Variables
Set AddPackage = Nothing
Set Command01 = Nothing
Set Image = Nothing
Set oShell = Nothing
Set PackagePath = Nothing
Set PackagePath_x86 = Nothing
Set PackagePath_x64 = Nothing
End Sub
'*******************************************************************************
Sub CreateFolderStructure(Architecture)
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM Command01 : Set Command01 = Nothing
DIM Directory : Set Directory = Nothing
DIM Directory_x86 : Directory_x86 = RelativePath & "Mount\CCTK\x86\HAPI"
DIM Directory_x64 : Directory_x64 = RelativePath & "Mount\CCTK\x86_64\HAPI"
If Architecture = "x86" Then
Directory = Directory_x86
Else
Directory = Directory_x64
End If
If NOT FSO.FolderExists(Directory) then
FSO.CreateFolder(Directory)
End If
REM Cleanup Local Variables
Set Command01 = Nothing
Set Directory = Nothing
Set Directory_x86 = Nothing
Set Directory_x64 = Nothing
Set FSO = Nothing
Set oShell = Nothing
End Sub
'*******************************************************************************
Sub CopyHAPIFiles(Architecture)
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM sCMD_1 : Set sCMD_1 = Nothing
DIM sCMD_2 : Set sCMD_2 = Nothing
DIM Source : Set Source = Nothing
DIM Source_x86 : Source_x86 = "C:\Program Files (x86)\Dell\CCTK\X86\HAPI\*.*"
DIM Source_x64 : Source_x64 = "C:\Program Files (x86)\Dell\CCTK\X86_64\HAPI\*.*"
DIM Dest : Set Dest = Nothing
DIM Dest_x86 : Dest_x86 = RelativePath & "mount\CCTK\x86\HAPI"
DIM Dest_x64 : Dest_x64 = RelativePath & "mount\CCTK\x86_64\HAPI"
If Architecture = "x86" Then
Source = Source_x86
Dest = Dest_x86
Else
Source = Source_x64
Dest = Dest_x64
End If
sCMD_1 = "%COMSPEC% /c mkdir " & Dest
If NOT FSO.FolderExists(Dest) then
oShell.Run sCMD_1, 1, True
End If
sCMD_2 = "%COMSPEC% /c copy " & Chr(34) & Source & Chr(34) & Chr(32) & Dest & Chr(32) & "/V /Y"
' If FSO.FolderExists(Source) then
oShell.Run sCMD_2, 1, True
' End If
REM Cleanup Local Variables
Set Dest = Nothing
Set Dest_x86 = Nothing
Set Dest_x64 = Nothing
Set FSO = Nothing
Set oShell = Nothing
Set sCMD_1 = Nothing
Set sCMD_2 = Nothing
Set Source = Nothing
Set Source_x86 = Nothing
Set Source_x64 = Nothing
End Sub
'*******************************************************************************
Sub CopyCCTKFiles(Architecture)
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
REM Define Local Variables
DIM CCTKFile : CCTKFile = "cctk.exe"
DIM MXMLFile : MXMLFile = "mxml1.dll"
DIM INIFile : INIFile = "multiplatform.ini"
DIM PCIFile : PCIFile = "pci.ids"
DIM NetSource : NetSource = "\\global.gsp\data\clients\na_clients\Dell\BIOS\"
DIM Source : Set Source = Nothing
DIM Source_x86 : Source_x86 = "C:\Program Files (x86)\Dell\CCTK\X86\"
DIM Source_x64 : Source_x64 = "C:\Program Files (x86)\Dell\CCTK\X86_64\"
DIM Dest : Set Dest = Nothing
DIM Dest_x86 : Dest_x86 = RelativePath & "mount\CCTK\x86\"
DIM Dest_x64 : Dest_x64 = RelativePath & "mount\CCTK\x86_64\"
If Architecture = "x86" Then
Source = Source_x86
Dest = Dest_x86
Else
Source = Source_x64
Dest = Dest_x64
End If
If NOT FSO.FolderExists(Dest) then
FSO.CreateFolder(Dest)
End If
If FSO.FolderExists(Source) then
FSO.CopyFile Source & CCTKFile, Dest, 1
End If
If FSO.FolderExists(Source) then
FSO.CopyFile NetSource & INIFile, Dest, 1
End If
If FSO.FolderExists(Source) then
FSO.CopyFile Source & PCIFile, Dest, 1
End If
If FSO.FolderExists(Source) then
FSO.CopyFile Source & MXMLFile, Dest, 1
End If
REM Cleanup Local Variables
Set CCTKFile = Nothing
Set INIFile = Nothing
Set MXMLFile = Nothing
Set PCIFile = Nothing
Set Dest = Nothing
Set Dest_x86 = Nothing
Set Dest_x64 = Nothing
Set FSO = Nothing
Set Source = Nothing
Set Source_x86 = Nothing
Set Source_x64 = Nothing
End Sub
'*******************************************************************************
Sub EditUnattend(Architecture)
REM Define Local Constants
CONST ForReading = 1
CONST ForWriting = 2
REM Define Local Objects
DIM File : File = "C:\winpe\mount\unattend.xml"
DIM strOld1 : strOld1 = "<Order>1</Order>"
DIM strNew1 : strNew1 = "<Order>4</Order>"
DIM strOld2 : strOld2 = "<RunSynchronous>"
DIM strNew2 : strNew2 = "<RunSynchronous>" & Chr(10) &_
"<RunSynchronousCommand wcm:action=" & Chr(34) & "add" & Chr(34) & ">" & Chr(10) &_
"<Description>Map BIOS Drive</Description>" & Chr(10) &_
"<Order>1</Order>" & Chr(10) &_
"<Path>net use \\global.gsp\data\clients\na_clients\dell\bios /user:win2kload 2kosload</Path>" & Chr(10) &_
"</RunSynchronousCommand>" & Chr(10) &_
"<RunSynchronousCommand wcm:action=" & Chr(34) & "add" & Chr(34) & ">" & Chr(10) &_
"<Description>Initiate HAPI</Description>" & Chr(10) &_
"<Order>2</Order>" & Chr(10) &_
"<Path>X:\CCTK\x86_64\HAPI\hapint -i -k C-C-T-K -p X:\CCTK\x86_64\HAPI\</Path>" & Chr(10) &_
"</RunSynchronousCommand>" & Chr(10) &_
"<RunSynchronousCommand wcm:action=" & Chr(34) & "add" & Chr(34) & ">" & Chr(10) &_
"<Description>Set BIOS Settings</Description>" & Chr(10) &_
"<Order>3</Order>" & Chr(10) &_
"<Path>x:\CCTK\x86_64\cctk.exe -i \\global.gsp\data\clients\na_clients\Dell\BIOS\multiplatform.ini</Path>" & Chr(10) &_
"</RunSynchronousCommand>"
DIM objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
DIM objFile : Set objFile = objFSO.getFile(File)
DIM objTextStream : Set objTextStream = objFile.OpenAsTextStream(ForReading)
DIM strInclude : strInclude = objTextStream.ReadAll
objTextStream.Close
Set objTextStream = Nothing
If InStr(strInclude,strOld1) > 0 Then
strInclude = Replace(strInclude,strOld1,strNew1)
Set objTextStream = objFile.OpenAsTextStream(ForWriting)
objTextStream.Write strInclude
objTextSTream.Close
Set objTextStream = Nothing
End If
If InStr(strInclude,strOld2) > 0 Then
strInclude = Replace(strInclude,strOld2,strNew2)
Set objTextStream = objFile.OpenAsTextStream(ForWriting)
objTextStream.Write strInclude
objTextSTream.Close
Set objTextStream = Nothing
End If
REM Cleanup Local Variables
Set File = Nothing
Set objFile = Nothing
Set objFSO = Nothing
Set objTextStream = Nothing
Set strInclude = Nothing
Set strNew1 = Nothing
Set strNew2 = Nothing
Set strOld1 = Nothing
Set strOld2 = Nothing
End Sub
'*******************************************************************************
Sub DismountWIM()
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM MountDIR : MountDIR = RelativePath & "Mount"
DIM Command01 : Command01 = "DISM /Unmount-WIM /MountDir:" & MountDIR & Chr(32) & "/commit"
oShell.Run Command01, 1, True
REM Cleanup Local Variables
Set Command01 = Nothing
Set MountDIR = Nothing
Set oShell = Nothing
End Sub
'*******************************************************************************
Sub Complete()
MsgBox "Process Complete"
End Sub
'*******************************************************************************
Sub GlobalVariableCleanup()
Set LogFolder = Nothing
Set RelativePath = Nothing
End Sub