-
Notifications
You must be signed in to change notification settings - Fork 1
/
LTIApply.wsf
executable file
·1666 lines (1155 loc) · 57.3 KB
/
LTIApply.wsf
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<job id="LTIApply">
<script language="VBScript" src="ZTIBCDUtility.vbs"/>
<script language="VBScript" src="ZTIConfigFile.vbs"/>
<script language="VBScript" src="ZTIDiskUtility.vbs"/>
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
' // ***************************************************************************
' //
' // Copyright (c) Microsoft Corporation. All rights reserved.
' //
' // Microsoft Deployment Toolkit Solution Accelerator
' //
' // File: LTIApply.wsf
' //
' // Version: 6.3.8330.1000
' //
' // Purpose: Apply image (OS or PE) to the hard drive
' //
' // Usage: cscript.exe [//nologo] LTIApply.wsf [/debug:true] [/pe] [/post]
' //
' // ***************************************************************************
Option Explicit
RunNewInstance
'//----------------------------------------------------------------------------
'// Main Class
'//----------------------------------------------------------------------------
Class LTIApply
'//----------------------------------------------------------------------------
'// Class instance variable declarations
'//----------------------------------------------------------------------------
' Global ConfigFile object
Dim oOSXMLDom
' A dictionary object for all operating systems Guid,XMLDomNode
Dim oOperatingSystems
' an XMLDomNode object of the OS item selected
Dim oOS
Dim sOSBuild
Dim sArchitecture
Dim sDestinationDrive
'//----------------------------------------------------------------------------
'// Constructor to initialize needed global objects
'//----------------------------------------------------------------------------
Private Sub Class_Initialize
sArchitecture= oEnvironment.Item("ImageProcessor")
If sArchitecture = "" then
sArchitecture = oEnvironment.Item("Architecture")
oLogging.CreateEntry "ImageProcessor not set, will boot into Windows PE architecture " & sArchitecture, LogTypeInfo
Else
oLogging.CreateEntry "Will boot into Windows PE architecture " & sArchitecture & " to match OS being deployed.", LogTypeInfo
End if
End Sub
'//----------------------------------------------------------------------------
'// Main routine
'//----------------------------------------------------------------------------
Function Main
Dim iRetVal
Dim sFile
Dim sSetup
Dim sLTIBootstrap
Dim iRC
iRetVal = Success
sDestinationDrive = oUtility.GetOSTargetDriveLetter
'//----------------------------------------------------------------------------
'// See what we need to do
'//----------------------------------------------------------------------------
If oUtility.Arguments.Exists("pe") then
' Put PE into place as the bootable OS
iRetVal = InstallPE
ElseIf oUtility.Arguments.Exists("post") then
' Call the cleanup routine
iRetVal = PostCleanup
Else
' Get the OS record
set oOSXMLDom = new ConfigFile
oOSXMLDom.sFileType = "OperatingSystems"
set oOperatingSystems = oOSXMLDom.FindItems
TestAndFail oOperatingSystems.exists(oEnvironment.Item("OSGUID")), 5601,"Verify OS guid: %OSGUID% exists."
set oOS = oOperatingSystems.Item(oEnvironment.Item("OSGUID"))
TestAndFail not(oOS is Nothing), 5602, "Open XML with OSGUID: %OSGUID%"
sOSBuild = "0"
sFile = ""
sSetup = ""
If not oOS.SelectSingleNode("Build") is nothing then
sOSBuild = oOS.SelectSingleNode("Build").Text
End if
If not oOS.SelectSingleNode("ImageFile") is nothing then
sFile = oOS.SelectSingleNode("ImageFile").Text
End if
If not oOS.SelectSingleNode("IncludesSetup") is nothing then
sSetup = oOS.SelectSingleNode("IncludesSetup").Text
End if
' Apply the specified image
If sFile = "" then
iRetVal = UnattendedInstall
ElseIf oEnvironment.Item("IsOSUpgrade") <> "" and oEnvironment.Item("IsOSUpgrade") = "1" then
iRetVal = UpgradeOS
Else
iRetVal = ApplyImage( "nt60" )
End if
' Make sure the LTIBootstrap.vbs script is copied to the root of the drive
If not oFSO.FileExists(sDestinationDrive & "\LTIBootstrap.vbs") then
iRC = oUtility.FindFile("LTIBootstrap.vbs", sLTIBootstrap)
oFSO.CopyFile sLTIBootstrap, sDestinationDrive & "\LTIBootstrap.vbs"
End if
End if
Main = iRetval
End Function
'//---------------------------------------------------------------------------
'// Function: InstallPE()
'// Purpose: Install Windows PE on the hard drive and make it the default OS
'//---------------------------------------------------------------------------
Function InstallPE()
Dim iRC
Dim oFile
Dim sFile
Dim sDir
Dim sGUID
Dim sBootDrive
Dim sScript
Dim oBootDrive
Dim aDiskArray
Dim sCmd
Dim iTotal
Dim iFreeSpace
Dim iBootFileSize
Dim sBCDStore
Dim sBootFile
Dim sBootMuiFile
InstallPE = Success
If not oUtility.Arguments.Exists("bcd") then
oLogging.CreateEntry "Get the Boot Drive.", LogTypeInfo
' This is a SysPrep capture, put WinPE on the Active(boot) partition.
If oEnvironment.Item("ImageBuild") <> "" then
set oBootDrive = GetBootDriveEx ( true, oEnvironment.Item("ImageBuild"), false )
ElseIf oEnvironment.Item("OSCurrentVersion") <> "" then
set oBootDrive = GetBootDriveEx ( true, oEnvironment.Item("OSCurrentVersion"), false )
Else
set oBootDrive = GetBootDriveEx ( true, "0.0.0.0", false )
End if
If not oBootDrive is nothing then
sBootDrive = oBootDrive.Drive
oLogging.CreateEntry "Setting Boot drive to: " & sBootDrive, LogTypeInfo
Else
oLogging.CreateEntry "Boot Drive not found, attempting recovery option (Win8+Sysprep scenario)...", LogTypeInfo
aDiskArray = Empty
on error resume next
aDiskArray = oUtility.BDDUtility.HiddenPartitionsToDrives
on error goto 0
For each sCmd in aDiskArray
If ubound(split(sCmd,vbTab)) >= 7 then
If trim(split(sCmd,vbTab)(3)) = "1" then
oLogging.CreateEntry "Found Recovery option: " & sCmd, LogTypeInfo
sBootDrive = left(split(sCmd,vbTab)(7),2)
Exit for
End if
End if
Next
TestAndFail not isEmpty(sBootDrive), 5609, "Boot Drive was not found."
End if
' Determine which architecture of PE we should install
sDir = oEnvironment.Item("DeployRoot") & "\Boot\LiteTouchPE_" & sArchitecture & ".wim"
TestAndFail oFSO.FileExists( sDir ), 5610, "Verify File: " & sDir
iFreeSpace = oFSO.GetDrive(sBootDrive).FreeSpace / 1024
oLogging.CreateEntry "Available space on boot drive: " & iFreeSpace, LogTypeInfo
iBootFileSize = oFSO.GetFile(sDir).Size / 1024
oLogging.CreateEntry "Boot file size: " & iBootFileSize, LogTypeInfo
If iFreeSpace < (iBootFileSize + 20000 ) and oEnvironment.item("BootDrive") = "" then
oLogging.CreateEntry "Not enough space for boot image on boot partition using system partition - " & left(oEnv("SystemDrive"),2), LogTypeInfo
sBootDrive = left(oEnv("SystemDrive"),2)
End if
oEnvironment.item("BootDrive") = sBootDrive
oLogging.CreateEntry "Ready to Prepare boot partition: " & sBootDrive, LogTypeInfo
oLogging.CreateEntry "------ Applying bootable Windows PE image ------", LogTypeInfo
oLogging.CreateEvent 41018, LogTypeInfo, "LTI applying Windows PE", Array()
' Copy bootmgr
If not oFSO.FileExists(sBootDrive & "\Bootmgr") then
oLogging.CreateEntry "Copying " & oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\bootmgr to " & sBootDrive & "\bootmgr", LogTypeInfo
oFSO.CopyFile oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\bootmgr", sBootDrive & "\", true
Else
iRC = ResetFile(sBootDrive & "\bootmgr")
If oFSO.FolderExists(sBootDrive & "\boot") then
iRC = ResetFolder(sBootDrive & "\boot")
End if
oLogging.CreateEntry "Copying " & oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\bootmgr to " & sBootDrive & "\bootmgr", LogTypeInfo
iRC = oUtility.RunWithConsoleLogging("cmd /c Attrib " & sBootDrive & "\bootmgr -H -S -R")
iRC = oUtility.RunWithConsoleLogging("cmd /c copy " & oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\bootmgr " & sBootDrive & "\")
oLogging.CreateEntry "Copying " & oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\boot\memtest.exe to " & sBootDrive & "\boot\memtest.exe", LogTypeInfo
iRC = oUtility.RunWithConsoleLogging("cmd /c copy " & oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\boot\memtest.exe " & sBootDrive & "\boot\memtest.exe")
End if
' Copy the PE boot image
oLogging.CreateEntry "Copying " & oEnvironment.Item("DeployRoot") & "\Boot\LiteTouchPE_" & sArchitecture & ".wim to " & sBootDrive & "\sources\boot.wim", LogTypeInfo
If not oFSO.FolderExists(sBootDrive & "\sources") then
oFSO.CreateFolder sBootDrive & "\sources"
End if
If oFSO.FileExists(sBootDrive & "\sources\boot.wim") then
oLogging.CreateEntry "Resetting attributes on existing boot.wim file in preparation for copying.", LogTypeInfo
oFSO.GetFile(sBootDrive & "\sources\boot.wim").Attributes = 0
End if
If MulticastCopy(oEnvironment.Item("DeployRoot") & "\Boot\LiteTouchPE_" & sArchitecture & ".wim", sBootDrive & "\sources\boot.wim") = "" then
oFSO.CopyFile oEnvironment.Item("DeployRoot") & "\Boot\LiteTouchPE_" & sArchitecture & ".wim", sBootDrive & "\sources\boot.wim", true
oLogging.CreateEntry "Windows PE WIM file copied successfully.", LogTypeInfo
Else
oLogging.CreateEntry "Windows PE WIM file successfully transferred using multicast.", LogTypeInfo
End if
' Copy the boot files
If ucase(oEnvironment.Item("IsUEFI")) = "TRUE" then
For each sDir in Array( "efi", "Boot" )
oUtility.RunWithConsoleLogging "robocopy.exe /mir /ndl /njs /njh """ & oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\" & sDir & """ """ & sBootDrive & "\" & sDir & """ /xf BCD* "
Next
oUtility.RunWithConsoleLogging "robocopy.exe /e /ndl /njs /njh """ & sBootDrive & "\efi\boot"" """ & sBootDrive & "\efi\Microsoft\boot"" /xf BCD* "
If UCase(sArchitecture) = "X64" then
sBootFile = "bootx64.efi"
sBootMuiFile = "bootx64.efi.mui"
Else
sBootFile = "bootia32.efi"
sBootMuiFile = "bootia32.efi.mui"
End if
oFileHandling.MoveFile sBootDrive & "\EFI\Microsoft\Boot\" & sBootFile, sBootDrive & "\EFI\Microsoft\Boot\BootMgFW.efi"
oUtility.RunWithConsoleLogging "cmd.exe /c for /r """ & sBootDrive & "\EFI\Microsoft\Boot"" %i in ( " & sBootMuiFile & " ) do if exist ""%i"" rename ""%i"" BootMgFW.efi.mui"
Else ' not IsUEFI
For each sDir in Array("boot", "boot\fonts")
oLogging.CreateEntry "Copying Boot folders and files", LogTypeInfo
If not oFSO.FolderExists(sBootDrive & "\" & sDir) then
oFSO.CreateFolder sBootDrive & "\" & sDir
End if
For each oFile in oFSO.GetFolder(oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\" & sDir).Files
If oFSO.FileExists(sBootDrive & "\" & sDir & "\" & oFile.Name) then
' Do nothing, file is already there
oLogging.CreateEntry "Skipping existing " & oFile.Name & " file.", LogTypeInfo
Else
oLogging.CreateEntry "Copying " & oFile.Path & " to " & sBootDrive & "\" & sDir & "\" & oFile.Name, LogTypeInfo
oFSO.CopyFile oFile.Path, sBootDrive & "\" & sDir & "\" & oFile.Name, true
End if
Next
Next
End if
' If Vista or above, copy the script and its dependencies locally as they'll be needed to prep the BCD later
If oEnvironment.Item("OSCurrentVersion") <> "" then
oUtility.GetMajorMinorVersion(oEnvironment.Item("OSCurrentVersion"))
If oUtility.VersionMajor >= 6 then
oUtility.VerifyPathExists oEnvironment.Item("_SMSTSMDataPath") & "\Scripts"
For each sScript in Array("LTIApply.wsf", "ZTIBCDUtility.vbs", "ZTIConfigFile.vbs", "ZTIDiskUtility.vbs", "ZTIUtility.vbs", "ZTIDataAccess.vbs")
oLogging.CreateEntry "Copying " & oUtility.ScriptDir & "\" & sScript & " to " & oEnvironment.Item("_SMSTSMDataPath") & "\Scripts\" & sScript, LogTypeInfo
oFSO.CopyFile oUtility.ScriptDir & "\" & sScript, oEnvironment.Item("_SMSTSMDataPath") & "\Scripts\" & sScript, true
Next
End if
End if
End if
' We need to set up the BCD to boot into Windows PE. If we are currently running XP/2003, we need to do this
' now while we can still get to BCDEDIT. For Vista and above, we must do it later so that Sysprep doesn't
' complain.
If oUtility.VersionMajor < 6 or not oUtility.Arguments.Exists("stage") then
' Retrieve the boot drive calculated earlier
sBootDrive = oEnvironment.Item("BootDrive")
If oEnvironment.Item("OSVersion") = "WinPE" and UCase(oEnvironment.Item("IsUEFI")) = "TRUE" then
sBCDStore = sBootDrive & "\efi\microsoft\boot\bcd"
If not oFSO.FileExists(sBCDStore) then
oFSO.CopyFile oEnvironment.Item("DeployRoot") & "\Boot\" & sArchitecture & "\EFI\Microsoft\Boot\BCD", sBCDStore
oFSO.GetFile(sBCDStore).Attributes = 0
End if
Else
sBCDStore = ""
End if
' Create the RamDisk Store for MDT
If isBCDEditReady then
BCDBackupStore sBootDrive & "\boot\bcd.save"
sGUID = BDD_RAMDISK_GUID
iRC = CreateNewBCDEntryEx ( sBCDStore, sGUID, "Microsoft Deployment WinPE", sBootDrive, "\sources\boot.wim" )
iRC = BCDObjectExistsEx( sBCDStore, sGUID )
TestAndLog iRC, "BCDObjectExistsEx(sBCDStore, " & BDD_RAMDISK_GUID & " )"
iRC = AdjustBCDDefaults ( sBCDStore, sGUID )
End if
' Get major and minor version
oUtility.GetMajorMinorVersion( oEnvironment.Item("OSCurrentVersion"))
' Make sure the \minint drive is visible!
If oUtility.VersionMajor <= 6 AND oUtility.VersionMinor < 1 then
RunDiskPartSilent( array ( "Select Volume " & sDestinationDrive, "Attributes Volume Clear NoDefaultDriveLetter", "Exit" ) )
End if
' Install the Longhorn boot sector if we are on XP (already present if on Vista or later)
If oUtility.VersionMajor < 6 then
oLogging.CreateEntry "Executing BOOTSECT.EXE to install a Vista boot sector", LogTypeInfo
iRC = oUtility.FindExeAndRunWithLogging( "bootsect.exe", "/nt60 " & sBootDrive & " /mbr" )
If iRC <> 0 then
oLogging.CreateEntry "Non-zero return code from BOOTSECT.EXE, may not support /MBR switch; trying again without", LogTypeInfo
iRC = oUtility.FindExeAndRunWithLogging( "bootsect.exe", "/nt60 " & sBootDrive )
End if
oLogging.CreateEntry "Boot sector upgraded, reboot is required.", LogTypeInfo
End if
oEnvironment.item("BootPE") = "True"
End if
oLogging.CreateEvent 41019, LogTypeInfo, "LTI Windows PE applied successfully", Array()
End Function
Function GetWDSServer
GetWDSServer = oUtility.SelectSingleNodeStringEx( oOS, "WDSServer", False)
If GetWDSServer <> "" and oEnvironment.Item("WDSServer") <> "" then
GetWDSServer = oEnvironment.Item("WDSServer")
End if
End function
Function GetSourcePath
GetSourcePath = oUtility.SelectSingleNodeStringEx(oOS,"ImageFile", False)
If Left(GetSourcePath, 1) = "." or GetSourcePath = "" then
If GetWDSServer <> "" then
GetSourcePath = "\\" & GetWDSServer & "\REMINST" & Mid(GetSourcePath, 2)
Else
GetSourcePath = oEnvironment.Item("DeployRoot") & Mid(GetSourcePath, 2)
End if
End if
End function
'//---------------------------------------------------------------------------
'// Function: UpgradeOS()
'// Purpose: Upgrade existing os to Windows 10 or above
'//---------------------------------------------------------------------------
Function UpgradeOS()
Dim iRC
Dim sImagePath
Dim sImageIndex
Dim sImagePlatform
Dim sCmd
Dim sSourcePath
Dim sSetupPath
Dim oDiskPart
UpgradeOS = Success
oUtility.GetMajorMinorVersion(oEnvironment.Item("ImageBuild"))
If oUtility.VersionMajor < 10 then
oLogging.CreateEntry "Upgrade is supported only for Windows 10 and above." , LogTypeError
UpgradeOS = Failure
Exit Function
End if
oLogging.CreateEntry "------ Upgrading Windows ------", LogTypeInfo
oLogging.CreateEntry "Verify we have necessary files locally, if not, copy it", LogTypeInfo
If Not OFSO.FileExists(oUtility.LocalRootPath & ":\MININT\Scripts\SetupComplete.cmd") Then
oShell.Run "wscript.exe """ & oUtility.ScriptDir & "\LTICopyScripts.wsf""", 0, true
End If
sImagePath = GetSourcePath
sImageIndex = oUtility.SelectSingleNodeString(oOS,"ImageIndex")
sImagePlatform = oUtility.SelectSingleNodeString(oOS,"Platform")
' Set the "SourcePath" property so it can be used later (if needed)
sSourcePath = oUtility.SelectSingleNodeString(oOS,"Source")
If Left(sSourcePath, 1) = "." then
sSourcePath = oEnvironment.Item("DeployRoot") & Mid(sSourcePath, 2)
End if
oEnvironment.Item("SourcePath") = sSourcePath
sSetupPath = sSourcePath & "\setup.exe"
oLogging.CreateEvent 41020, LogTypeInfo, "LTI upgrade OS using " & sSourcePath, Array()
TestAndFail oFSO.FileExists( sSetupPath ), 5630, "Verify File: " & sSetupPath
' Check the size
set oDiskPart = new ZTIDiskPartition
oDiskPart.Drive= sDestinationDrive
TestAndFail not oDiskPart.oWMIDiskPart is nothing, 5604, "Verify Destination Drive is defined(1)"
TestAndFail not oDiskPart.oWMIDrive(false) is nothing, 5605, "Verify Destination Drive is defined(2)"
If (oDiskPart.oWMIDiskPart.Size /1000 /1000) < (GetMinimumDiskPartitionSizeMB) then
oLogging.CreateEntry "Destination Drive May be too small: " & FormatLargeSize(oDiskPart.oWMIDiskPart.Size) & " Needed: " & FormatLargeSize( GetMinimumDiskPartitionSizeMB * 1000 * 1000 ), LogTypeInfo
ElseIf (oDiskPart.oWMIDrive(false).FreeSpace /1000 /1000) < (GetMinimumDiskPartitionSizeMB) then
oLogging.CreateEntry "Destination Drive May not have enough free space: " & FormatLargeSize(oDiskPart.oWMIDrive(false).FreeSpace) & " Needed: " & FormatLargeSize( GetMinimumDiskPartitionSizeMB * 1000 * 1000 ), LogTypeInfo
End if
' Generate upgrade command
sCmd = """" & sSetupPath & """" & " /auto Upgrade /Quiet /NoReboot" & " /PostOobe " & oUtility.LocalRootPath & "\Scripts\SetupComplete.cmd" & " /PostRollback " & oUtility.LocalRootPath & "\Scripts\SetupRollback.cmd"
If oEnvironment.Item("OSUpgradeDriverPath") <> "" then
sCmd = sCmd & " /InstallDrivers " & oEnvironment.Item("OSUpgradeDriverPath")
End if
if oEnvironment.Item("ProductKey") <> "" then
sCmd = sCmd & " /Pkey " & oEnvironment.Item("ProductKey")
End if
If CInt(oEnvironment.Item("DynamicallyUpdateWinSetup")) = 1 then
sCmd = sCmd & " /DynamicUpdate Enable"
Else
sCmd = sCmd & " /DynamicUpdate Disable"
End if
If oEnvironment.Item("WindowsUpgradeAdditionalOptions") <> "" then
sCmd = sCmd & " " & oEnvironment.Item("WindowsUpgradeAdditionalOptions")
End if
If oEnvironment.Item("ImageIndex") <> "" then
sCmd = sCmd & " /ImageIndex " & oEnvironment.Item("ImageIndex")
End if
oLogging.CreateEntry "Upgrading from " & sSetupPath & " using command: " & sCmd, LogTypeInfo
oLogging.ReportProgress "Upgrade OS", 70
iRC = oUtility.RunWithHeartbeat(sCmd)
If iRC = 0 then
oLogging.CreateEvent 41021, LogTypeInfo, "Setup completed successfully.", Array()
oLogging.CreateEntry "Requesting reboot for setup.exe to complete Upgrade action", LogTypeInfo
oLogging.ReportProgress "Requesting Reboot", 80
oEnvironment.Item("SMSTSRebootRequested") = "true"
UpgradeOS = iRC
Else
oLogging.CreateEvent 41022, LogTypeError, "Setup failed to upgrade OS from " & sSetupPath & ", rc = " & iRC, Array(iRC)
UpgradeOS = Failure
End if
End Function
'//---------------------------------------------------------------------------
'// Function: ApplySetup()
'// Purpose: Apply the specified Windows Vista image using Setup
'//---------------------------------------------------------------------------
Function ApplySetup()
Dim iRC
Dim sImagePath
Dim sImageIndex
Dim sImagePlatform
Dim sWorkingDir
Dim sCmd
Dim oOperatingSystem
Dim sIncludesSetup
Dim sBuild
Dim sPlatform
Dim sSource
Dim sFlags
Dim oNode
Dim oAvailableLanguages
Dim aKeys
Dim sKey
Dim oUnattend
Dim sLocalPath
Dim bMatchingPlatform
Dim aDiskArray
Dim oDiskPart
ApplySetup = Success
oLogging.CreateEntry "------ Applying Windows image using Setup.exe ------", LogTypeInfo
sImagePath = GetSourcePath
sImageIndex = oUtility.SelectSingleNodeString(oOS,"ImageIndex")
sImagePlatform = oUtility.SelectSingleNodeString(oOS,"Platform")
bMatchingPlatform = UCase(sImagePlatform) = UCase(oEnvironment.Item("Architecture"))
' See if we can get the file via multicast
sLocalPath = MulticastCopy(sImagePath, "")
If sLocalPath <> "" then
sImagePath = sLocalPath
End if
oLogging.CreateEvent 41020, LogTypeInfo, "LTI applying image " & sImagePath & " using SETUP.EXE", Array()
If not oFSO.FileExists(sImagePath) then
oUtility.ValidateConnection sImagePath
End if
TestAndFail oFSO.FileExists( sImagePath ), 5630, "Verify File: " & sImagePath
' Find setup path
If bMatchingPlatform and oFSO.FileExists(oFSO.GetParentFolderName(sImagePath) & "\Sources\Setup.exe") then
sWorkingDir = oFSO.GetParentFolderName(sImagePath) & "\Sources"
ElseIf bMatchingPlatform and oFSO.FileExists(oFSO.GetParentFolderName(sImagePath) & "\Setup.exe") then
sWorkingDir = oFSO.GetParentFolderName(sImagePath)
Else
' Find SETUP somewhere else
For each oOperatingSystem in oOperatingSystems.Items
' Get the details for the currently-selected OS
sIncludesSetup = ""
sBuild = ""
sPlatform = ""
sSource = ""
sFlags = ""
On Error Resume Next
sIncludesSetup = UCase(oUtility.SelectSingleNodeString(oOperatingSystem,"IncludesSetup"))
sBuild = oUtility.SelectSingleNodeString(oOperatingSystem,"Build")
sPlatform = UCase(oUtility.SelectSingleNodeString(oOperatingSystem,"Platform"))
sSource = oEnvironment.Item("DeployRoot") & Mid(oUtility.SelectSingleNodeString(oOperatingSystem,"Source"), 2)
On Error Goto 0
If not oOperatingSystem.SelectSingleNode("Flags") is nothing then
sFlags = ucase(oOperatingSystem.SelectSingleNode("Flags").Text)
End if
' See if it will work
If sIncludesSetup = "TRUE" and sPlatform = UCase(oEnvironment.Item("Architecture")) and left(sBuild,8) = left(oEnvironment.Item("ImageBuild"),8) then
sWorkingDir = sSource & "\Sources"
oLogging.CreateEntry "Found a matching SETUP in " & sWorkingDir, LogTypeInfo
Exit For
End if
Next
' Make sure we found SETUP
If sWorkingDir = "" then
' If we can't find SETUP.EXE, fall back to using DISM.exe. This will work
' for any image except for the original Windows Vista INSTALL.WIM (because it
' is configured to boot from D:\WINDOWS). However, we will assume that
' we won't run into INSTALL.WIM without setup files.
oLogging.CreateEntry "Unable to find SETUP, use DISM.exe as a backup.", LogTypeInfo
ApplySetup = ApplyImage ( "nt60" )
Exit Function
End if
End if
' Load the unattend.xml
Set oUnattend = oUtility.CreateXMLDOMObjectEx(oUtility.LocalRootPath & "\unattend.xml")
aDiskArray = Empty
On error resume next
aDiskArray = oUtility.BDDUtility.HiddenPartitionsToDrives
On error goto 0
' Make sure the disk index is set correctly in the unattend.xml
If not isEmpty(aDiskArray) then
Set oNode = oUnattend.selectSingleNode("//settings[@pass=""windowsPE""]/component[@name=""Microsoft-Windows-Setup""]/ImageInstall/OSImage/InstallTo/PartitionID")
If not (oNode is Nothing) then
For each sCmd in aDiskArray
If ubound(split(sCmd,vbTab)) >= 7 then
If split(sCmd,vbTab)(7) <> "" then
If ucase(left(split(sCmd,vbTab)(7),2)) = ucase(left(sDestinationDrive,2)) then
If trim(oNode.Text) <> trim(split(sCmd,vbTab)(2)) then
oLogging.CreateEntry "IOCTL_STORAGE_GET_DEVICE_NUMBER reports a different number: " & sCmd, LogTypeInfo
oNode.Text = trim(split(sCmd,vbTab)(2))
oUnattend.Save oUtility.LocalRootPath & "\unattend.xml"
End if
End if
End if
End if
Next
End if
End if
' Make sure the image path is set correctly in the unattend.xml
Set oNode = oUnattend.selectSingleNode("//settings[@pass=""windowsPE""]/component[@name=""Microsoft-Windows-Setup""]/ImageInstall/OSImage/InstallFrom/Path")
If not (oNode is Nothing) then
If oNode.Text <> sImagePath then
oLogging.CreateEntry "Updating unattend.xml to change image path from " & oNode.Text & " to " & sImagePath, LogTypeInfo
oNode.Text = sImagePath
oUnattend.Save oUtility.LocalRootPath & "\unattend.xml"
End if
End if
' Figure out the SetupUILanguage
Set oAvailableLanguages = oUtility.SectionContents(sWorkingDir & "\lang.ini", "Available UI Languages")
If oAvailableLanguages.Count > 0 then
aKeys = oAvailableLanguages.Keys
sKey = aKeys(0)
' Find the SetupUILanguage entry
Set oNode = oUnattend.selectSingleNode("//settings[@pass=""windowsPE""]/component[@name=""Microsoft-Windows-International-Core-WinPE""]/SetupUILanguage/UILanguage")
If not (oNode is Nothing) then
If oNode.Text <> sKey then
oLogging.CreateEntry "Updating unattend.xml to change Setup UI Language from " & oNode.Text & " to " & sKey, LogTypeInfo
oNode.Text = sKey
oUnattend.Save oUtility.LocalRootPath & "\unattend.xml"
End if
End if
End if
' Clean off old OS if running in PE
If oEnvironment.Item("OSVersion") = "WinPE" then
oLogging.ReportProgress "Cleaning drive", 20
CleanDrive
End if
' VDS COM object (used in DiskPart and in WMI) *may* complain if run too quickly. Add 30 sec delay
If isNumeric(oEnvironment.Item("VDSCOMDelaySeconds")) then
oLogging.CreateEntry "Pause (seconds): " & oEnvironment.Item("VDSCOMDelaySeconds"), LogTypeInfo
oUtility.SafeSleep cint(oEnvironment.Item("VDSCOMDelaySeconds")) * 1000
Else
oLogging.CreateEntry "Pause (seconds): 15 ", LogTypeInfo
oUtility.SafeSleep 15 * 1000
End if
' Check the size
set oDiskPart = new ZTIDiskPartition
oDiskPart.Drive= sDestinationDrive
TestAndFail not oDiskPart.oWMIDiskPart is nothing, 5604, "Verify Destination Drive is defined(1)"
TestAndFail not oDiskPart.oWMIDrive(false) is nothing, 5605, "Verify Destination Drive is defined(2)"
If (oDiskPart.oWMIDiskPart.Size /1000 /1000) < (GetMinimumDiskPartitionSizeMB) then
oLogging.CreateEntry "Destination Drive May be too small: " & FormatLargeSize(oDiskPart.oWMIDiskPart.Size) & " Needed: " & FormatLargeSize( GetMinimumDiskPartitionSizeMB * 1000 * 1000 ), LogTypeInfo
ElseIf (oDiskPart.oWMIDrive(false).FreeSpace /1000 /1000) < (GetMinimumDiskPartitionSizeMB) then
oLogging.CreateEntry "Destination Drive May not have enough free space: " & FormatLargeSize(oDiskPart.oWMIDrive(false).FreeSpace) & " Needed: " & FormatLargeSize( GetMinimumDiskPartitionSizeMB * 1000 * 1000 ), LogTypeInfo
End if
' Get setup to apply the image (ZTIConfigure copied Unattend.xml to the Target)
sCmd = """" & sWorkingDir & "\setup.exe"" /noreboot /unattend:" & oUtility.LocalRootPath & "\unattend.xml"
If FindOEM <> "" then
sCmd = sCmd & " /m:""" & FindOEM & """"
End if
oLogging.CreateEntry "Installing image from " & sImagePath & " using command: " & sCmd, LogTypeInfo
oLogging.ReportProgress "Installing image", 50
' Do not display the SCCM Progress bar during Windows Vista & Windows 7 setup
On error resume next
CreateObject("Microsoft.SMS.TSProgressUI").CloseProgressDialog
On error goto 0
oEnvironment.Item("LTIDirtyOS") = "TRUE"
iRC = oUtility.RunWithHeartbeat(sCmd)
oLogging.ReportProgress "Done Installing image", 100
If iRC = 0 then
oLogging.CreateEvent 41021, LogTypeInfo, "Setup completed successfully.", Array()
Else
oLogging.CreateEvent 41022, LogTypeError, "Setup failed applying image " & sImagePath & ", rc = " & iRC, Array(iRC)
End if
ApplySetup = iRC
End Function
'//---------------------------------------------------------------------------
'//
'// Function: ApplyImage()
'//
'// Input: sVersion
'//
'// Return: Success - 0
'// Failure - non-zero
'//
'// Purpose: Apply the specified Windows image to the machine.
'//
'//---------------------------------------------------------------------------
Function ApplyImage( sVersion )
Dim iRC
Dim sImagePath
Dim sImageIndex
Dim sSourcePath
Dim sCmd
Dim sDISM
Dim sLocalPath
Dim sRWMPath
DIM sSWMPath
Dim oBootDrive
Dim oDiskPart
ApplyImage = Success
oLogging.CreateEntry "------ Applying Windows image using DISM.exe ------", LogTypeInfo
sImagePath = GetSourcePath
sImageIndex = oUtility.SelectSingleNodeString(oOS,"ImageIndex")
oLogging.CreateEvent 41023, LogTypeInfo, "LTI applying image " & sImagePath & " using DISM", Array()
If not oFSO.FileExists(sImagePath) then
oUtility.ValidateConnection sImagePath
End if
TestAndFail oFSO.FileExists( sImagePath ), 5640, "Verify File: " & sImagePath
' Set the "SourcePath" property so it can be used later (if needed)
sSourcePath = oUtility.SelectSingleNodeString(oOS,"Source")
If Left(sSourcePath, 1) = "." then
sSourcePath = oEnvironment.Item("DeployRoot") & Mid(sSourcePath, 2)
End if
oEnvironment.Item("SourcePath") = sSourcePath
' See if we can get the file via multicast
sLocalPath = MulticastCopy(sImagePath, "")
If sLocalPath <> "" then
sImagePath = sLocalPath
End if
' If WDS, look for an RWM file
If GetWDSServer <> "" then
sRWMPath = oFSO.GetParentFolderName(sImagePath) & "\RES.RWM"
If oFSO.FileExists(sRWMPath) then
' See if we can get that file via multicast
sLocalPath = MulticastCopy(sRWMPath, "")
If sLocalPath <> "" then
sRWMPath = sLocalPath
End if
Else
sRWMPath = ""
End if
ElseIf ucase(right(sImagePath,4)) = ".SWM" then
sSWMPath =""
sSWMPath = mid(sImagePath,1,len(sImagePath)-4) & "*.swm"
oLogging.CreateEntry "Found SWM file, adding other SWM files for concatenation: " & sSWMPath, LogTypeInfo
End if
' Clean off old OS if running in PE
If oEnvironment.Item("OSVersion") = "WinPE" then
oLogging.ReportProgress "Cleaning drive", 1
CleanDrive
End if
' Check the size
set oDiskPart = new ZTIDiskPartition
oDiskPart.Drive= sDestinationDrive
TestAndFail not oDiskPart.oWMIDiskPart is nothing, 5606, "Verify Destination Drive is defined(1)"
TestAndFail not oDiskPart.oWMIDrive(false) is nothing, 5607, "Verify Destination Drive is defined(2)"
If (oDiskPart.oWMIDiskPart.Size /1000 /1000) < (GetMinimumDiskPartitionSizeMB) then
oLogging.CreateEntry "Destination Drive May be too small: " & FormatLargeSize(oDiskPart.oWMIDiskPart.Size) & " Needed: " & FormatLargeSize( GetMinimumDiskPartitionSizeMB * 1000 * 1000 ), LogTypeInfo
ElseIf (oDiskPart.oWMIDrive(false).FreeSpace /1000 /1000) < (GetMinimumDiskPartitionSizeMB) then
oLogging.CreateEntry "Destination Drive May not have enough free space: " & FormatLargeSize(oDiskPart.oWMIDrive(false).FreeSpace) & " Needed: " & FormatLargeSize( GetMinimumDiskPartitionSizeMB * 1000 * 1000 ), LogTypeInfo
End if
' If deploying something less than Windows 8, make sure 8dot3 support is enabled. Diskpart in Windows PE 4.0
' leaves 8dot3 off by default.
' Get major and minor version
oUtility.GetMajorMinorVersion(sOSBuild)
If oUtility.VersionMajor < 6 OR (oUtility.VersionMajor = 6 AND oUtility.VersionMinor < 2) then
oLogging.CreateEntry "Enabling 8dot3 name support on volume " & sDestinationDrive, LogTypeInfo
On Error Resume Next
oShell.Run "fsutil.exe 8dot3name set " & sDestinationDrive & " 0", 0, true
On Error Goto 0
End if
' Apply the image
sCmd = " /Apply-Image /ImageFile:""" & sImagePath & """"
If sRWMPath <> "" then
sCmd = sCmd & " /SWMFile:""" & sRWMPath & """"
End if
If sSWMPath <> "" then
sCmd = sCmd & " /SWMFile:""" & sSWMPath & """"
End if
sCmd = sCmd & " /Index:" & sImageIndex & " /ApplyDir:" & sDestinationDrive
oLogging.ReportProgress "Applying image", 1
iRC = oUtility.FindExeAndRunWithLogging( "DISM.exe", sCmd )
TestAndFail iRC, 5624, "Run DISM: " & sCmd
oEnvironment.Item("LTIDirtyOS") = "TRUE"
oLogging.CreateEvent 5625, LogTypeInfo, "The image " & sImagePath & " was applied successfully.", Array()
' Install a boot sector
If ucase(oEnvironment.Item("IsUEFI")) <> "TRUE" then
iRC = oUtility.FindExeAndRunWithLogging( "bootsect.exe", " /" & sVersion & " " & sDestinationDrive )
TestAndFail iRC, 5626, "Verify BootSect.exe returned Successfully."
End if
If sVersion = "nt52" then
' Clean up boot and bootmgr
oFileHandling.RemoveFolder sDestinationDrive & "\Boot"
oFileHandling.DeleteFileEx sDestinationDrive & "\BootMgr", false
Else
' Windows 7/2008R2 Specific commands for preping the machine
If oEnvironment.Item("ImageBuild") <> "" then
set oBootDrive = GetBootDriveEx ( true, oEnvironment.Item("ImageBuild"), false )
ElseIf oEnvironment.Item("OSCurrentVersion") <> "" then
set oBootDrive = GetBootDriveEx ( true, oEnvironment.Item("OSCurrentVersion"), false )
Else
set oBootDrive = GetBootDriveEx ( true, "0.0.0.0", false )
End if
TestAndFail not oBootDrive is nothing, 5615, "Boot Drive was not found, required? "
oLogging.CreateEntry "Ready to Prepare boot partition: " & oBootDrive.Drive, LogTypeInfo
' Create a new boot entry for the new OS using BCDBoot.exe.
If ucase(oEnvironment.Item("IsUEFI")) = "TRUE" then
' Remove old BCD, as it might get in the way
If oFSO.FileExists(Left(oBootDrive.Drive,2) & "\efi\microsoft\boot\bcd") then
oLogging.CreateEntry "Removing existing BCD so it can be recreated using BCDBOOT.", LogTypeInfo
oFSO.DeleteFile Left(oBootDrive.Drive,2) & "\efi\microsoft\boot\bcd", true
End if
' When using Windows ADK, specify that we want to update the UEFI BCD (in firmware).
' When using Windows AIK, don't specify a store as it *should* figure it out.
If oEnvironment.Item("OSCurrentVersion") <> "" then
oUtility.GetMajorMinorVersion( oEnvironment.Item("OSCurrentVersion"))
If ((oUtility.VersionMajor = 6 and oUtility.VersionMinor >= 2) or oUtility.VersionMajor >= 10 )then
TestAndFail RunBCDBootEx( sDestinationDrive & "\windows", " /s " & left(oBootDrive.Drive,2) & " /f UEFI"), 5616, "Verify BCDBootEx"
Else
TestAndFail RunBCDBootEx( sDestinationDrive & "\windows", " "), 5616,"Verify BCDBootEx"
End if
End if
' Make sure the boot menu timeout is 0
RunBCDEdit "/timeout 0"
Else
' Remove old BCD, as it might get in the way
On Error Resume Next
If oEnvironment.Item("VHDDisks") <> "" then
oLogging.CreateEntry "Skip Removal of BCD files in VHD Scenarios.", LogTypeInfo
ElseIf oFSO.FileExists(Left(oBootDrive.Drive,2) & "\boot\bcd") then
oLogging.CreateEntry "Removing existing BCD so it can be recreated using BCDBOOT.", LogTypeInfo
oFSO.DeleteFile Left(oBootDrive.Drive,2) & "\boot\bcd", true