-
Notifications
You must be signed in to change notification settings - Fork 1
/
LiteTouch.wsf
executable file
·1729 lines (1088 loc) · 53 KB
/
LiteTouch.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="LiteTouch">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript" src="ZTIDataAccess.vbs"/>
<script language="VBScript" src="ZTIDiskUtility.vbs"/>
<script language="VBScript">
' // ***************************************************************************
' //
' // Copyright (c) Microsoft Corporation. All rights reserved.
' //
' // Microsoft Deployment Toolkit Solution Accelerator
' //
' // File: Litetouch.wsf
' //
' // Version: 6.3.8330.1000
' //
' // Purpose: Drive the lite touch deployment process
' //
' // Usage: cscript LiteTouch.wsf [/debug:true]
' //
' // ***************************************************************************
Option Explicit
Dim oLiteTouch
Dim iScriptRC
Dim bUpgradeSuccess
If not oUtility.Arguments.Exists("DebugCapture") Then
On Error Resume Next
End If
Set oLiteTouch = new Litetouch
TestAndFail SUCCESS, 5400, "Create object: Set oLiteTouch = New Litetouch"
iScriptRc = oLiteTouch.Main
Wscript.quit iScriptRc
'//----------------------------------------------------------------------------
'// Global Constants
'//----------------------------------------------------------------------------
'//----------------------------------------------------------------------------
'// Main Class
'//----------------------------------------------------------------------------
Class Litetouch
'//----------------------------------------------------------------------------
'// Class instance variable declarations
'//----------------------------------------------------------------------------
'//----------------------------------------------------------------------------
'// Constructor to initialize needed global objects
'//----------------------------------------------------------------------------
Private Sub Class_Initialize
End Sub
'//----------------------------------------------------------------------------
'// Main routine
'//----------------------------------------------------------------------------
Function Main
Dim oProgressWiz
Dim iRetVal
Dim oLink
Dim sCmd
Dim sBootstrap, sTSPath, sFile
Dim i
Dim oDrive
Dim oShellApp
Dim bTSInProgress
Dim sSource
Dim bIsAdmin
Dim oAssocs
Dim oAssoc
Dim bFoundMedia
Dim sPlat
Dim sProcessorArchitecture
Dim bIsOEM
Dim oTS
Dim sOriginalDeployRoot
Dim sOSVer
Dim oInstances
Dim oInstance
Dim sFinishAction
Dim bSkipFinalSummary
Dim bIsServerCoreOS
Dim sWizard
Dim sDisableDiskMgr
Dim iCurrentOSVerMajor
Dim sUpgradeFailureCode
iRetVal = Success
' Check for administrative rights if we are using Xp or Windows 2003.
' If not then throw error and exit script.
' Check OS version
Set oInstances = objWMI.ExecQuery("select * from Win32_OperatingSystem")
For Each oInstance In oInstances
sOSVer = oInstance.Version
Next
On Error Resume Next
' Check if we can write to the windows folder
oFSO.CreateTextFile(oEnv("SystemRoot") & "\authtest.txt")
oUtility.GetMajorMinorVersion(sOSVer)
iCurrentOSVerMajor = oUtility.VersionMajor
If (iCurrentOSVerMajor < 6) and Err <> 0 and (ucase(oEnv("SystemDrive")) <> "X:") then
oShell.Popup "You do not have the correct permissions to perform this deployment. Please run as a local administrator.", 0, "Permissions Error", 16
WScript.Quit iRetVal
End if
Err.clear
On Error Goto 0
' Temporary adding support for legacy Javascript until fix is included in WinPE
If ucase(oEnv("SystemDrive")) = "X:" then
oUtility.RegWrite "HKLM\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_USE_LEGACY_JSCRIPT\mshta.exe", 1
End if
' Are we dirty?
If oEnvironment.Item("LTIDirty") = "TRUE" or (oEnvironment.Item("LTIDirtyOS") = "TRUE" and (not oUtility.Arguments.Exists("start"))) then
i = oShell.Popup("An existing in-progress deployment was found but is not in an expected state. Would you like to ignore this in-progress deployment and start a new one?", 0, "Dirty Environment Found", 4+48)
If i = 6 then
QuickCleanup
oLogging.CreateEntry "Cleaned up a dirty deployment.", LogTypeInfo
Else
oLogging.CreateEntry "User chose to continue a dirty deployment.", LogTypeInfo
End if
End if
' If in PE, make sure the C: drive is a fixed disk. Otherwise, on a computer
' with no existing partitions on the first disk, the CD or USB drive can become C:.
' That causes issues when we later want to create a C: partition.
If oEnv("SystemDrive") = "X:" and oFSO.DriveExists("C:") then
' If the C: drive is removable, move it
If oFSO.GetDrive("C:").DriveType <> 2 then
MoveCDrive
End if
End if
' See if there is an in-progress task sequence
bTSInProgress = False
For each oDrive in oUtility.GetAllFixedDrives(false)
If oFSO.FileExists(oDrive & "\_SMSTaskSequence\TSEnv.dat") then
oLogging.CreateEntry "Found existing task sequence state information in " & oDrive & "\_SMSTaskSequence, will continue", LogTypeInfo
bTSInProgress = True
Exit For
End if
Next
If not bTSInProgress then
oLogging.CreateEntry "No task sequence is in progress.", LogTypeInfo
End if
If oUtility.Arguments.Exists("CleanStart") then
oLogging.CreateEntry "This script was started from litetouch.vbs with the /CleanStart switch. Clean existing instances of MDT.", LogTypeInfo
QuickCleanup
bTSInProgress = False
End if
' Make sure there's no unattend.xml to get in the way if we're just getting started
If not bTSInProgress then
If oFSO.FileExists(oEnv("SystemDrive") & "\Windows\Panther\unattend\unattend.xml") then
oLogging.CreateEntry "Removing old " & oEnv("SystemDrive") & "\Windows\Panther\unattend\unattend.xml", LogTypeInfo
oFSO.DeleteFile oEnv("SystemDrive") & "\Windows\Panther\unattend\unattend.xml", true
TestAndLog SUCCESS, "Removed " & oEnv("SystemDrive") & "\Windows\Panther\unattend\unattend.xml"
End if
End if
' Clean up the LTIBootstrap.vbs file if it exists
If oFSO.FileExists(oEnv("SystemDrive") & "\LTIBootstrap.vbs") then
On Error Resume Next
oFSO.DeleteFile oEnv("SystemDrive") & "\LTIBootstrap.vbs", true
On Error Goto 0
End if
'Set the Task Sequence files to the first possible system drive (if available)
If oEnvironment.Item("PHASE") = "" Then
oEnvironment.Item("SMSTSLocalDataDrive") = GetFirstPossibleSystemDrive
oUtility.VerifyPathExists oEnvironment.Item("SMSTSLocalDataDrive") & "\MININT\SMSOSD\OSDLOGS"
oUtility.ResetLocalRootPath
End If
'//----------------------------------------------------------------------------
'// If starting in the new OS, create a shortcut to run once the shell starts
'//----------------------------------------------------------------------------
If oUtility.Arguments.Exists("start") then
If (oEnvironment.Item("IsOSUpgrade") <> "" and oEnvironment.Item("IsOSUpgrade") = "1") then
oLogging.CreateEntry "Running OS Upgrade", LogTypeInfo
Else
' Remove the LTIDirtyOS flag as we're getting into the new OS exactly how we expected
oEnvironment.Item("LTIDirtyOS") = "FALSE"
' Create the startup group item if needed
SetStartMDT
If oFSO.FileExists(oEnv("SystemRoot") & "\Explorer.exe") and UCase(oEnvironment.Item("HideShell")) <> "YES" then
Main = Success
Exit Function
End If
End If
End if
'//----------------------------------------------------------------------------
'// Test for the existance of a recovery session, and if present, call WinRE.
'//----------------------------------------------------------------------------
TestForWinREAndLaunch
'//----------------------------------------------------------------------------
'// Set the deployment method
'//----------------------------------------------------------------------------
bFoundMedia = False
For Each oDrive in oFSO.Drives
If oDrive.IsReady then
If oFSO.FileExists(oDrive.DriveLetter & ":\Deploy\Scripts\Media.tag") then
bFoundMedia = True
oEnvironment.Item("DeployRoot") = oDrive.DriveLetter & ":\Deploy"
oEnvironment.Item("ResourceRoot") = oDrive.DriveLetter & ":\Deploy"
oEnvironment.Item("DeploymentMethod") = "MEDIA"
Exit For
End if
End if
Next
' If we already know we're doing a media deployment and we can't find the media,
' prompt to have it reinserted
If oEnvironment.Item("DeploymentMethod") = "MEDIA" and not bFoundMedia then
bFoundMedia = False
Do While not bFoundMedia
oLogging.CreateEntry "Unable to find media, prompting to have it reinserted", LogTypeInfo
oShell.Popup "Please reinsert the media (CD, DVD, or USB) needed to complete the deployment.", 0, "Media not found", 48
For Each oDrive in oFSO.Drives
If oDrive.IsReady then
If oFSO.FileExists(oDrive.DriveLetter & ":\Deploy\Scripts\Media.tag") then
bFoundMedia = True
oEnvironment.Item("DeployRoot") = oDrive.DriveLetter & ":\Deploy"
oEnvironment.Item("ResourceRoot") = oDrive.DriveLetter & ":\Deploy"
oEnvironment.Item("DeploymentMethod") = "MEDIA"
Exit For
End if
End if
Next
Loop
End if
' If no media found and we don't know the deployment method, it must be UNC.
If oEnvironment.Item("DeploymentMethod") = "" then
oEnvironment.Item("DeploymentMethod") = "UNC"
End if
oLogging.CreateEntry "DeploymentMethod = " & oEnvironment.Item("DeploymentMethod"), LogTypeInfo
'//----------------------------------------------------------------------------
'// If there were any "saved" network settings, restore them now.
'//----------------------------------------------------------------------------
If isNumeric(oEnvironment.Item("OSDAdapterCount")) then
If Cint(oEnvironment.Item("OSDAdapterCount")) > 0 then
sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTINicConfig.wsf"" /RestoreWithinWinPE"
iRetVal = RunAndLog(sCmd, true)
TestAndLog iRetVal,"Excution: " & sCmd
End if
End if
'//----------------------------------------------------------------------------
'// Find the "real" DeployRoot
'//----------------------------------------------------------------------------
If oEnvironment.Item("DeploymentMethod") = "UNC" then
' Set the DeployRoot based on where we were started from
If oEnvironment.Item("DeployRoot") = "" then
oEnvironment.Item("DeployRoot") = oFSO.GetParentFolderName(oUtility.ScriptDir)
End if
ValidateDeployRootWithRecovery
End if
oLogging.CreateEntry "DeployRoot = " & oEnvironment.Item("DeployRoot"), LogTypeInfo
oEnvironment.Item("DeployDrive") = oUtility.FindMappedDrive(oEnvironment.Item("DeployRoot"))
oLogging.CreateEntry "DeployDrive = " & oEnvironment.Item("DeployDrive"), LogTypeInfo
'//----------------------------------------------------------------------------
'// Gather information
'//----------------------------------------------------------------------------
' Set the phase if it isn't already set
If oEnvironment.Item("PHASE") = "" or (oEnvironment.Item("IsOSUpgrade") <> "" and oEnvironment.Item("IsOSUpgrade") = "1") then
If oEnv("SystemDrive") = "X:" then ' Running in PE
oEnvironment.Item("PHASE") = "PREINSTALL"
If oEnvironment.Item("DeploymentType") = "" then
oEnvironment.Item("DeploymentType") = "NEWCOMPUTER"
End if
Else
oEnvironment.Item("PHASE") = "VALIDATION"
If oEnvironment.Item("IsOSUpgrade") = "1" then
oEnvironment.Item("DeploymentType") = "UPGRADE"
oEnvironment.Item("PHASE") = ""
oLogging.CreateEntry "This is Upgrade, setting Phase = (empty)" & oEnvironment.Item("Phase"), LogTypeInfo
ElseIf oEnvironment.Item("DeploymentType") = "" then
oEnvironment.Item("DeploymentType") = "REFRESH"
End if
End if
End if
oLogging.CreateEntry "Phase = " & oEnvironment.Item("Phase"), LogTypeInfo
' Do the full gathering process and display the wizard the first time, otherwise
' just refresh the environment
If (oEnvironment.Item("PHASE") = "VALIDATION") or (oEnvironment.Item("PHASE") = "PREINSTALL" and oEnvironment.Item("DeploymentType") = "NEWCOMPUTER") then
' Try to create the welcome wizard to display progress
oLogging.ReportProgress "Initializing.", 1
On Error Resume Next
Set oProgressWiz = Nothing
sCmd = "MSHTA.exe """ & oUtility.ScriptDir & "\Wizard.hta"" /definition:BDD_Welcome_ENU.xml"
Set oProgressWiz = oShell.Exec(sCmd)
On Error Goto 0
' Process bootstrap rules
sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTIGather.wsf"" /inifile:Bootstrap.ini"
iRetVal = RunAndLog(sCmd, true)
TestAndLog iRetVal,"Running " & sCMD
sOriginalDeployRoot = oEnvironment.Item("DeployRoot")
' As long as the wizard was displayed, wait for it to finish
If not (oProgressWiz is Nothing) then
' Wait for the wizard to exit or to indicate a choice
Do While oProgressWiz.Status = 0
WScript.Sleep 200
Loop
' Was the wizard cancelled? If so, exit
If UCase(oEnvironment.Item("SkipBDDWelcome")) <> "YES" and oEnvironment.Item("WizardComplete") <> "Y" then
Cleanup
oLogging.ReportFailure "Welcome wizard failed or was cancelled", 5212
End if
End if
' If there were any "saved" network settings. Restore them now.
If isNumeric(oEnvironment.Item("OSDAdapterCount")) then
If Cint(oEnvironment.Item("OSDAdapterCount")) > 0 then
sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTINicConfig.wsf"" /RestoreWithinWinPE"
iRetVal = RunAndLog(sCmd, true)
TestAndLog iRetVal,"Excution: " & sCmd
End if
End if
' Enable DaRT remote control (for Windows PE)
EnableDaRT
' Set the keyboard if necessary
If oEnv("SystemDrive") = "X:" and oEnvironment.Item("KeyboardLocalePE") <> "" then
sCmd = right("0000" & Hex(GetLocale),4) & ":" & right("00000000" & Hex(GetLocale), 8)
If UCase(oEnvironment.Item("KeyboardLocalePE")) <> UCase( sCmd ) then
sCmd = "wpeutil.exe SetKeyboardLayout " & oEnvironment.Item("KeyboardLocalePE")
RunAndLog sCmd, false
End if
End if
' Validate connection (if DeployRoot has changed)
ValidateDeployRootWithRecovery
' Validate we are running as an administrator
On error resume next
bIsAdmin = oUtility.BDDUtility.IsAdmin
On error goto 0
If oEnv("SystemDrive") = "X:" then ' Running in PE
' OK if running within WinPE
ElseIf isempty(bIsAdmin) then
' BDDUtility not found, default to OK
ElseIf bIsAdmin = FALSE then
oShell.Popup "You must be running with Administrator rights. The deployment cannot proceed.", 0, "Wizard Error", 16
oLogging.ReportFailure "The logged-on user does not have Administrator rights.", 5204
End if
' Try to create the welcome wizard to display progress of CustomSettings.ini
oLogging.ReportProgress "Initializing.", 1
On Error Resume Next
Set oProgressWiz = Nothing
sCmd = "MSHTA.exe """ & oUtility.ScriptDir & "\Wizard.hta"" /definition:WelcomeWiz_Initialize.xml"
Set oProgressWiz = oShell.Exec(sCmd)
On Error Goto 0
' Process full rules. If DeployRoot is blank or still pointing to PE, this is optional.
oLogging.ReportProgress "Processing full rules.", 50
If Left(UCase(oEnvironment.Item("DeployRoot")), 3) = "X:\" or oEnvironment.Item("DeployRoot") = "" then
sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTIGather.wsf"" /nolocalonly /optional"
Else
sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTIGather.wsf"" /nolocalonly"
End if
iRetVal = RunAndLog(sCmd, true)
TestAndLog iRetVal, "Running " & sCMD
' Validate connection (if DeployRoot has changed)
ValidateDeployRootWithRecovery
' If a task sequence ID was set, populate the other properties
If oEnvironment.Item("TaskSequenceID") <> "" then
oUtility.SetTaskSequenceProperties Ucase(oEnvironment.Item("TaskSequenceID"))
End if
oLogging.ReportProgress "Initialization complete.", 100
' As long as the wizard was displayed, wait for it to finish
If not (oProgressWiz is Nothing) then
' Wait for the progress wizard to exit (should already be shutting down)
Do While oProgressWiz.Status = 0
WScript.Sleep 200
Loop
End if
' If DeployRoot changed, validate the connection again and re-process rules
If sOriginalDeployRoot <> oEnvironment.Item("DeployRoot") then
' Validate connection
ValidateDeployRootWithRecovery
' Process full rules again
sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTIGather.wsf"" /nolocalonly"
iRetVal = RunAndLog(sCmd, true)
TestAndLog iRetVal, "Running " & sCMD
End if
' Display the deployment wizard (unless skipped)
oEnvironment.Item("LTIDirty") = "TRUE"
If UCase(oEnvironment.Item("SkipWizard")) <> "YES" then
sCmd = "MSHTA.exe """ & oEnvironment.Item("DeployRoot") & "\Scripts\Wizard.hta"" /definition:DeployWiz_Definition_ENU.xml"
iRetVal = RunAndLog(sCmd, true)
TestAndLog iRetVal, "Running " & sCMD
' Make sure the wizard completed
If oEnvironment.Item("WizardComplete") <> "Y" then
oShell.Popup "The Deployment Wizard was cancelled or did not complete successfully. The deployment will not proceed.", 0, "Wizard Error", 16
Cleanup
oLogging.ReportFailure "The Deployment Wizard was cancelled or did not complete successfully. The deployment will not proceed.", 5206
End if
End if
' Validate the DeploymentType value
Select Case UCase(oEnvironment.Item("DeploymentType"))
Case "NEWCOMPUTER", "REFRESH", "REPLACE", "CUSTOM", "STATERESTORE", "UPGRADE"
oLogging.CreateEntry "Validated DeploymentType, value = " & oEnvironment.Item("DeploymentType"), LogTypeVerbose
Case Else
oShell.Popup "Invalid DeploymentType value """ & oEnvironment.Item("DeploymentType") & """ specified. The deployment will not proceed.", 0, "Deployment Error", 16
oLogging.CreateEntry "Invalid DeploymentType value """ & oEnvironment.Item("DeploymentType") & """ specified.", LogTypeError
Cleanup
oLogging.ReportFailure "Invalid DeploymentType value """ & oEnvironment.Item("DeploymentType") & """ specified.", 5208
End Select
' Clean up properties if the wizard was skipped
If UCase(oEnvironment.Item("SkipWizard")) = "YES" then
If oEnvironment.Item("JoinDomain") = "" and oEnvironment.Item("JoinWorkgroup") = "" then
SetPropertyDefault "JoinWorkgroup", "WorkGroup", "Join basic workgroup"
End if
If UCase(oEnvironment.Item("DeploymentType")) = "UPGRADE" and oEnvironment.Item("IsOSUpgrade") = "" then
SetPropertyDefault "IsOSUpgrade", "1", "Wizard is skipped and we are performing upgrade, setting IsOSUpgrade = 1"
End if
SetPropertyDefault "ComputerBackupLocation", "NONE", "Do not backup"
SetPropertyDefault "UserDataLocation", "NONE", "Empty Strings break automation"
SetPropertyDefault "TimeZoneName", "Pacific Standard Time", "Set TimeZone to some default"
If oEnvironment.Item("JoinDomain") <> "" Then
SetPropertyDefault "DomainAdmin", oEnvironment.Item("UserID"), "Use the credentials supplied for DomainJoin"
SetPropertyDefault "DomainAdminDomain", oEnvironment.Item("UserDomain"), "Use the credentials supplied for DomainJoin"
SetPropertyDefault "DomainAdminPassword", oEnvironment.Item("UserPassword"), "Use the credentials supplied for DomainJoin"
End if
End if
' For the management pack, set OSDComputerName in some cases
If Ucase(oEnvironment.Item("ComputerName")) <> "" AND Ucase(OEnvironment.Item("OSDComputerName")) = "" Then
oEnvironment.Item("OSDComputerName") = oEnvironment.Item("ComputerName")
End If
If oEnvironment.Item("OSDComputerName") = "" Then
If oUtility.ComputerName = "" Then
If oEnvironment.Item("HostName") <> "" Then
oEnvironment.Item("OSDComputerName") = oEnvironment.Item("HostName")
Else
oEnvironment.Item("OSDComputerName") = oENV("ComputerName")
End If
End If
End If
'Set the USMT TagFile if storing to a local drive
If Mid(oEnvironment.Item("UserDataLocation"),2,1) = ":" Then
Dim USMTTagFile
On Error Resume Next
If not oFSO.FileExists(Left(oEnvironment.Item("UserDataLocation"), 2) & "\UserState.tag") Then
Set USMTTagFile = OFSO.CreateTextFile(Left(oEnvironment.Item("UserDataLocation"), 2) & "\UserState.tag", true)
If Err Then
oLogging.CreateEntry "Invalid UserDataLocation specified", LogTypeError
Main = Failure
Exit Function
End If
USMTTagFile.Close
End If
End If
Else
' Enable DaRT remote control (for Windows PE)
EnableDaRT
End if
ValidateDeployRootWithRecovery
oEnvironment.Item("DeployDrive") = oUtility.FindMappedDrive(oEnvironment.Item("DeployRoot"))
oLogging.CreateEntry "DeployDrive = " & oEnvironment.Item("DeployDrive"), LogTypeInfo
If oEnvironment.Item("ResourceRoot") = "" then
oEnvironment.Item("ResourceRoot") = oEnvironment.Item("DeployRoot")
Else
oUtility.ValidateConnectionEx oEnvironment.Item("ResourceRoot"), True
End if
oLogging.CreateEntry "DeploymentType = " & oEnvironment.Item("DeploymentType"), LogTypeInfo
oLogging.CreateEntry "ResourceRoot = " & oEnvironment.Item("ResourceRoot"), LogTypeInfo
oEnvironment.Item("ResourceDrive") = oUtility.FindMappedDrive(oEnvironment.Item("ResourceRoot"))
oLogging.CreateEntry "ResourceDrive = " & oEnvironment.Item("ResourceDrive"), LogTypeInfo
'//----------------------------------------------------------------------------
'// Process the task sequence
'//----------------------------------------------------------------------------
' Set the task sequence name
If oEnvironment.Item("_SMSTSPackageName") = "" then
oEnvironment.Item("_SMSTSPackageName") = "Lite Touch Installation"
End if
oShell.Environment("PROCESS")("SEE_MASK_NOZONECHECKS") = 1
' Verify the Processor_Architecture and replace if necessary.
sProcessorArchitecture = oEnv("Processor_Architecture")
If ucase(sProcessorArchitecture) = "AMD64" then
sProcessorArchitecture = "x64"
End if
If ucase(oEnvironment.Item("Architecture")) <> ucase(sProcessorArchitecture) then
oEnvironment.Item("Architecture") = sProcessorArchitecture
End if
' Set the script root path that should be used. (These can't be task sequence variables because
' we have no way of injecting new values into the task sequence environment before the task sequence
' resumes.)
oEnv("ScriptRoot") = oEnvironment.Item("DeployRoot") & "\Scripts"
oEnv("ToolRoot") = oEnvironment.Item("DeployRoot") & "\Tools\" & oEnvironment.Item("Architecture")
' Copy the task sequencer files if they aren't already on the drive
If oFSO.FileExists("X:\Deploy\Tools\" & oEnvironment.Item("Architecture") & "\TsmBootstrap.exe") then
oLogging.CreateEntry "SMS Task Sequencer already found on X:\Deploy\Tools\" & oEnvironment.Item("Architecture"), LogTypeInfo
sTSPath = "X:\Deploy\Tools\" & oEnvironment.Item("Architecture")
ElseIf oFSO.FileExists(oUtility.LocalRootPath & "\Tools\" & oEnvironment.Item("Architecture") & "\TsmBootstrap.exe") then
oLogging.CreateEntry "SMS Task Sequencer already found on " & oUtility.LocalRootPath & "\Tools\" & oEnvironment.Item("Architecture"), LogTypeInfo
sTSPath = oUtility.LocalRootPath & "\Tools\" & oEnvironment.Item("Architecture")
Else
iRetVal = oUtility.FindFile("TsmBootstrap.exe", sBootstrap)
If (iRetVal <> Success) then
oShell.Popup "Unable to find the SMS Task Sequencer. The deployment will not proceed.", 0, "Wizard Error", 16
oLogging.ReportFailure "Unable to find the SMS Task Sequencer. The deployment will not proceed.", 5208
End if
sSource = oFSO.GetParentFolderName(sBootstrap)
sTSPath = oUtility.LocalRootPath & "\Tools\" & oEnvironment.Item("Architecture")
oLogging.CreateEntry "SMS Task Sequencer found at " & sSource & ", copying to " & sTSPath, LogTypeInfo
If Left(sTSPath, 2) <> "X:" then ' Running from PE
oUtility.VerifyPathExists sTSPath & "\00000409"
For each sFile in Array("CcmCore.dll","CcmUtilLib.dll","Smsboot.exe","SmsCore.dll","TsCore.dll","TSEnv.exe","TsManager.exe","TsmBootstrap.exe","TsMessaging.dll","TsProgressUI.exe","TSResNlc.dll","msvcp120.dll","msvcr120.dll","CommonUtils.dll","ccmgencert.dll","00000409\tsres.dll")
oLogging.CreateEntry "Copying " & sSource & "\" & sFile & " to " & sTSPath & "\" & sFile, LogTypeInfo
oFSO.CopyFile sSource & "\" & sFile, sTSPath & "\" & sFile, true
Next
End if
End if
If not oFSO.FileExists(sTSPath & "\TS.XML") then
' Copy the appropriate TS.XML file
oUtility.VerifyPathExists sTSPath
oLogging.CreateEntry "Copying " & oEnvironment.Item("DeployRoot") & "\Control\" & oEnvironment.Item("TaskSequenceID") & "\TS.XML to " & sTSPath, LogTypeInfo
oFSO.CopyFile oEnvironment.Item("DeployRoot") & "\Control\" & oEnvironment.Item("TaskSequenceID") & "\TS.XML", sTSPath & "\TS.XML", true
' Copy the VARIABLES.DAT to where the task sequence can find it
If oFSO.FileExists(oEnvironment.PersistPath & "\" & oEnvironment.PersistFile) then
oLogging.CreateEntry "Copying " & oEnvironment.PersistPath & "\" & oEnvironment.PersistFile & " to " & sTSPath & "\VARIABLES.DAT", LogTypeInfo
oFSO.CopyFile oEnvironment.PersistPath & "\" & oEnvironment.PersistFile, sTSPath & "\VARIABLES.DAT", true
End if
End if
' Ensure that this machine does *not* go to sleep while running the task sequence steps.
On error resume next
oUtility.BDDUtility.KeepAlive
On error goto 0
' Wait for the shell if necessary
If UCase(oEnvironment.Item("HideShell")) = "YES" then
On Error Resume Next
oUtility.BDDUtility.WaitForShell
On Error Goto 0
End if
'Set the Max SMSTS.LOG size
ExtendSMSTSLogSize
' Run the task sequence
If bTSInProgress then
' Resume the task sequence
oUtility.GetOSTargetDriveLetterEx False
sCmd = """" & sTSPath & "\TsmBootstrap.exe"" /env:SAContinue"
Else
' Run the task sequence
oLogging.CreateEvent 41016, LogTypeInfo, "LTI beginning deployment", Array(oEnvironment.Item("DeploymentType"), oEnvironment.Item("DeploymentMethod"))
sCmd = """" & sTSPath & "\TsmBootstrap.exe"" /env:SAStart"
End if
oLogging.CreateEntry "About to run command: " & sCmd, LogTypeInfo
oEnvironment.Item("LTIDirty") = "TRUE"
On Error Resume Next
iRetVal = oShell.Run(sCmd,, true)
On Error Goto 0
' Unregister the task sequence components
On Error Resume Next
oShell.Run "regsvr32.exe /u /s """ & sTSPath & "\tscore.dll""", 0, true
oShell.Run """" & sTSPath & "\TSProgressUI.exe"" /Unregister", 0, true
On Error Goto 0
' Reset the local root path
oUtility.ResetLocalRootPath
oLogging.CreateEntry "Command completed, return code = " & iRetVal, LogTypeInfo
' Reboot if requested
If (iRetVal = -2147021886) then
oEnvironment.Item("LTIDirty") = "FALSE"
' Reset the Destination Logical Drive ( Drive letter may have changed after rebooting )
oUtility.ClearRelativeDriveLetters
oLogging.CreateEvent 41017, LogTypeInfo, "LTI initiating task sequence-requested reboot.", Array()
If oEnvironment.Item("DeploymentType") = "CUSTOM" Then
oEnvironment.Item("PHASE") = "CUSTOM"
End If
If oEnv("SystemDrive") = "X:" then
If oEnvironment.Item("LTISuspend") = "True" then
oShell.Popup "The task sequence has been suspended. Reboot WinPE (Close all windows) to resume.", 60, "Suspended", 48
ElseIf oEnvironment.Item("LTISuspend") <> "" then
oShell.Popup "The task sequence has been suspended." & VbNewLine & oEnvironment.Item("LTISuspend") & VbNewLine & "Reboot WinPE (Close all windows) to resume.", 60, "Suspended", 48
End if
WScript.Quit 0
Else
If oEnvironment.Item("BootPE") <> "True" and oEnvironment.Item("IsOSUpgrade") <> "1" then
PopulateAutoAdminLogon
End If
If oEnvironment.Item("LTISuspend") = "" then
If OEnvironment.Item("BootPE") <> "True" and oEnvironment.Item("IsOSUpgrade") <> "1" then
SetStartMDT
End If
'Reset the variable
oEnvironment.Item("BootPE") = ""
Reboot
WScript.Sleep 600000 ' Wait for the system to be rebooted out from under the script
Else
If oEnvironment.Item("LTISuspend") = "True" then
oShell.Popup "The task sequence has been suspended. Use the desktop shortcut to resume.", 60, "Suspended", 48
Else
oShell.Popup "The task sequence has been suspended." & VbNewLine & oEnvironment.Item("LTISuspend") & VbNewLine & "Use the desktop shortcut to resume.", 60, "Suspended", 48
End if
WScript.Quit 0
End if
End if
' Process is complete
Else
' Send an event
On Error Resume Next
sUpgradeFailureCode = oShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Windows\Win10UpgradeStatusCode")
If sUpgradeFailureCode <> "" and ucase(sUpgradeFailureCode) = "FAILURE" then
oLogging.CreateEvent 41014, LogTypeError, "Litetouch deployment failed during Upgrade " , Array()
oLogging.CreateEntry "For more information, consult the task sequencer log ...\SMSTS.LOG.", LogTypeInfo
iRetVal = oEnvironment.Item("UpgradeErrorReturnCode")
ElseIf iRetVal = 0 then
oLogging.CreateEvent 41015, LogTypeInfo, "LTI deployment completed successfully", Array("0")
If ucase(oEnvironment.Item("_DoNotCleanLiteTouch")) = "TRUE" then
bIsOEM = True
End if
Else
oLogging.CreateEvent 41014, LogTypeError, "Litetouch deployment failed, Return Code = " & PrnErrValue ( iRetval ), Array(CStr(iRetVal))
oLogging.CreateEntry "For more information, consult the task sequencer log ...\SMSTS.LOG.", LogTypeInfo
End if
' Pass the return code to the wizard
oEnvironment.Item("RetVal") = Trim(CStr(iRetVal))
' Copy the logs
oLogging.CopyLog
' Save variables that we need
sFinishAction = oEnvironment.Item("FinishAction")
bSkipFinalSummary = UCase(oEnvironment.Item("SkipFinalSummary")) = "YES"
bIsServerCoreOS = UCase(oEnvironment.Item("IsServerCoreOS")) = "TRUE"
sDisableDiskMgr = oEnvironment.Item("DisableTaskMgr")
' Copy needed summary wizard files to %TEMP%\DeploymentScripts
If (bSkipFinalSummary and iRetVal = 0) or bIsServerCoreOS then
' Do nothing
Else
oUtility.VerifyPathExists oEnvironment.Substitute("%TEMP%\DeploymentScripts")
For each sFile in Array("Wizard.hta", "Wizard.css", "Wizard.ico", "ZTIUtility.vbs", "WizUtility.vbs", "ZTIConfigFile.vbs", "ZTIDiskUtility.vbs", "ZTIDataAccess.vbs", "header-image.png", "Computer.png", "Summary_Definition_ENU.xml", "Summary_Scripts.vbs", "plusicon.gif", "minusico.gif")
oFSO.CopyFile oEnv("ScriptRoot") & "\" & sFile, oEnvironment.Substitute("%TEMP%\DeploymentScripts") & "\" & sFile, true
Next
End if
' Clean up
Cleanup
' Display the final summary wizard (unless skipped)
If (not bSkipFinalSummary) or iRetVal <> 0 then
If bIsServerCoreOS then
If iRetVal = 0 then
oShell.Popup "Deployment completed successfully. Review deployment logs for full details.", 0, "Successful Deployment", 64
Else
oShell.Popup "Deployment did not complete successfully. Review deployment logs for full details.", 0, "Failed Deployment", 48
End if
ElseIf bIsOEM = True then
i = oShell.Popup ( "The OEM Image has been copied to the local machine. Now ready for replication." & _
vbNewLine & vbNewLine & "Press OK (Enter) to shutdown (Default automatic shutdown in 20 minutes)." & _