-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeployWiz_OfflineData.vbs
executable file
·366 lines (275 loc) · 10.9 KB
/
DeployWiz_OfflineData.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
' // ***************************************************************************
' //
' // Copyright (c) Microsoft Corporation. All rights reserved.
' //
' // Microsoft Deployment Toolkit Solution Accelerator
' //
' // File: DeployWiz_OfflineData.vbs
' //
' // Version: 6.3.8330.1000
' //
' // Purpose: Scripts for offline data migration page
' //
' // ***************************************************************************
Option Explicit
Dim g_hasSomethingBeenChecked
Dim g_IsDisk0Bitlocked
dim g_OSDrive
Dim g_WindowsCount
Function AddDiskToTableByDll ( sCmd, EncryptedDrives )
Dim oRow
Dim oCol
Dim aCmd
Dim sDiskID
Dim sDiskDesc
Dim sSelected
Dim sType
Dim sArchitecture, sNewArchitecture
Dim sDrive
Dim iNewVerMajor, iVerMajor
AddDiskToTableByDll = false
oLogging.CreateEntry "Add Entry to Dialog: " & replace(sCmd,vbTab," "), LogTypeInfo
aCmd = split(sCmd,vbTab)
If aCmd(0) = "EMPTY" then
Exit Function
End if
oUtility.GetMajorMinorVersion(oEnvironment.Item("ImageBuild"))
iNewVerMajor = oUtility.VersionMajor
sNewArchitecture = UCase(oEnvironment.Item("ImageProcessor"))
sType = ""
sSelected = ""
sDiskDesc = "Disk " & aCmd(1) & " Partition " & aCmd(2)
sDiskID = "Disk" & aCmd(1) & "part" & aCmd(2)
If len(aCmd(7)) = 0 then
oLogging.CreateEntry "Nothing to display " & sDiskID & " OK TO Skip!", LogTypeInfo
exit function
ElseIf Instr(1,EncryptedDrives,left(aCmd(7),2),vbTextCompare) <> 0 then
' This drive is BitLockered
sDiskDesc = sDiskDesc & " <div style='display:inline; font: bold;' class='errmsg'>?? BitLocker Protected ??</div>"
sSelected = "disabled"
sType = ""
g_IsDisk0Bitlocked = g_IsDisk0Bitlocked or true ' (cint(aCmd(1)) = 0)
ElseIf ubound(aCmd) < 8 then
oLogging.CreateEntry "Nothing to display Disabled " & sDiskID & " OK TO Skip!", LogTypeInfo
exit function
ElseIf aCmd(5) < 10000 then
oLogging.CreateEntry "Partition too small " & sDiskID & " OK TO Skip! " & aCmd(5), LogTypeInfo
exit function
ElseIf aCmd(9) < 15000 then
' Not enough Free Space
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]"
oLogging.CreateEntry "Not enough disk space on " & sDiskID & " OK TO Skip! " & aCmd(5), LogTypeInfo
sSelected = "Unknown"
sType = "Drive Full"
Else
sDrive = Left(aCmd(7),2)
If oFSO.FileExists(sDrive & "\Windows\System32\ntoskrnl.exe") Then
oUtility.GetMajorMinorVersion(oFSO.GetFileVersion(sDrive & "\Windows\System32\ntoskrnl.exe"))
iVerMajor = oUtility.VersionMajor
If oFSO.FolderExists(sDrive & "\Program Files (x86)") then
sArchitecture = "X64"
Else
sArchitecture = "X86"
End if
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]" ' \Windows"
If sArchitecture = "X64" and sNewArchitecture = "X86" then
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]"
oLogging.CreateEntry "Existing OS is x64, new OS is x86, user state migration not supported.", LogTypeInfo
sSelected = "disabled"
sType = "Architecture changing from x64 to x86"
ElseIf iVerMajor <= iNewVerMajor then
sType = "\Windows " & iVerMajor
AddDiskToTableByDll = True
If g_hasSomethingBeenChecked <> true and cint(aCmd(1)) = 0 then
sSelected = "checked"
g_hasSomethingBeenChecked = true
g_OSDrive = sDrive
End if
Else
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]"
oLogging.CreateEntry "Existing OS " & sDiskID & " is too new, " & iVerMajor & " > " & iNewVerMajor, LogTypeInfo
sSelected = "disabled"
sType = "Too new operating system"
End if
ElseIf oFSO.FileExists(sDrive & "\Winnt\System32\ntoskrnl.exe") Then
oUtility.GetMajorMinorVersion(oFSO.GetFileVersion(sDrive & "\Winnt\System32\ntoskrnl.exe"))
iVerMajor = oUtility.VersionMajor
If oFSO.FolderExists(sDrive & "\Program Files (x86)") then
sArchitecture = "X64"
Else
sArchitecture = "X86"
End if
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]" ' \WinNT"
If sArchitecture = "X64" and sNewArchitecture = "X86" then
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]"
oLogging.CreateEntry "Existing OS is x64, new OS is x86, user state migration not supported.", LogTypeInfo
sSelected = "disabled"
sType = "Architecture changing from x64 to x86"
ElseIf iVerMajor <= iNewVerMajor then
sType = "\WinNT " & iVerMajor
AddDiskToTableByDll = True
If g_hasSomethingBeenChecked <> true and cint(aCmd(1)) = 0 then
sSelected = "checked"
g_hasSomethingBeenChecked = true
g_OSDrive = sDrive
End if
Else
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]"
oLogging.CreateEntry "Existing OS " & sDiskID & " is too new, " & iVerMajor & " > " & iNewVerMajor, LogTypeInfo
sSelected = "disabled"
sType = "Too new operating system"
End if
Else
sDiskDesc = sDiskDesc & " [" & aCmd(8) & "]"
sSelected = "disabled"
sType = "No operating system"
End if
End if
' # -------------------------------------
set oRow = document.createElement("<tr onmouseover=""javascript:this.className = 'DynamicListBoxRow-over';"" onmouseout=""javascript:this.className = 'DynamicListBoxRow';"" >")
set oCol = document.createElement("TD")
If instr(1,sSelected,"disabled",vbTextCompare) <> 0 then
oCol.innerHTML = "<input name='OfflineMigration' id='" & sDiskID & "' type='radio' value='' language=vbscript onclick='DriveSelected' " & sSelected & " />"
Else
oCol.innerHTML = "<input name='OfflineMigration' id='" & sDiskID & "' type='radio' value='" & left(aCmd(7),2) & "' language=vbscript onclick='DriveSelected' " & sSelected & " />"
End if
oRow.appendChild oCol
set oCol = document.createElement("TD")
oCol.innerHTML = "<label for='" & sDiskID & "' class=TreeItem >" & sDiskDesc & "</label>"
oRow.appendChild oCol
set oCol = document.createElement("TD")
oCol.innerHTML = FormatLargeSize(clng(aCmd(5)) * 1024 * 1024 )
oRow.appendChild oCol
set oCol = document.createElement("TD")
oCol.innerHTML = sType
oRow.appendChild oCol
DiskTable.FirstChild.appendChild oRow
End Function
Function InitializeOfflineDataPage
Dim i
Dim oDisk
Dim EncryptedDrives
g_IsDisk0Bitlocked = false
for each oDisk in GetObject("winmgmts:\\.\root\CIMV2\Security\MicrosoftVolumeEncryption"). _
ExecQuery("SELECT * FROM Win32_EncryptableVolume WHERE ProtectionStatus = 2",,48)
EncryptedDrives = EncryptedDrives & vbTab & oDisk.DriveLetter
next
oDisk = Empty
on error resume next
oDisk = oUtility.BDDUtility.HiddenPartitionsToDrives
on error goto 0
g_WindowsCount = 0
If not isEmpty(oDisk) then
for i = 0 to ubound(oDisk)
If ubound(split(oDisk(i),vbTab)) >= 8 then
If AddDiskToTableByDll(oDisk(i), EncryptedDrives) then
g_WindowsCount = g_WindowsCount + 1
End if
End if
next
End if
If g_IsDisk0Bitlocked = true and g_hasSomethingBeenChecked <> true then
oLogging.CreateEntry "A supported previous version of Windows was not found on this computer. Suspend BitLocker to save files and settings.", LogTypeInfo
UDRadio1.Checked = true
UDRadio2.disabled = true
MSITTExtInfo.style.display = "inline"
MSITText.InnerHTML = "A supported previous version of Windows was not found on this computer. Suspend BitLocker to save files and settings."
ElseIf g_WindowsCount = 0 then
oLogging.CreateEntry "A supported previous version of Windows was not found on this computer. Data and settings cannot be restored.", LogTypeInfo
UDRadio1.Checked = true
UDRadio2.disabled = true
MSITTExtInfo.style.display = "inline"
MSITText.InnerHTML = "A supported previous version of Windows was not found on this computer. Data and settings cannot be restored."
Else
If g_IsDisk0Bitlocked = true then
oLogging.CreateEntry "A BitLocker-protected drive was found. Suspend BitLocker to save files and settings.", LogTypeInfo
MSITTExtInfo.style.display = "inline"
MSITText.InnerHTML = "A BitLocker-protected drive was found. Suspend BitLocker to save files and settings."
End if
End if
If g_WindowsCount > 1 then
for each oDisk in document.getElementsByName("OfflineMigration")
oLogging.CreateEntry "OFfline Migration checked: [" & oProperties("OfflineMigration") & "] = [" & oDisk.Value & "]", LogTypeInfo
If oProperties("OfflineMigration") <> "" and oProperties("OfflineMigration") = oDisk.Value then
oDisk.checked = true
exit for
End if
next
MoreThanOneVolume.Style.Display = "inline"
if UDRadio1.Checked then
NoOffline
end if
End if
KeepPartitions.Disabled = true
If UDRadio1.Checked and g_WindowsCount > 0 then
KeepPartitions.Disabled = false
If oProperties("doNotFormatAndPartition") = "YES" then
KeepPartitions.checked = true
Else
KeepPartitions.checked = false
End if
End if
End function
' --------------------------
Function DriveSelected
g_OSDrive = window.event.srcElement.Value
oLogging.CreateEntry "Item Selected: " & g_OSDrive, LogTypeInfo
End function
Function OnlineEnable
Dim oDisk
for each oDisk in document.getElementsByName("OfflineMigration")
If oDisk.Value <> "" then
oDisk.Disabled = false
End if
next
KeepPartitions.Disabled = true
End function
Function NoOffline
Dim oDisk
for each oDisk in document.getElementsByName("OfflineMigration")
oDisk.Disabled = true
next
If g_WindowsCount > 0 then
KeepPartitions.Disabled = false
End if
End function
Function RemovePropertyIfPresent ( oProperty )
If oProperties.Exists( oProperty ) then
oProperties.remove oProperty
End if
End function
Function ValidateOfflineData
If UDRadio1.Checked then
oLogging.CreateEntry "No data to save", LogTypeInfo
If KeepPartitions.Checked then
oProperties("doNotFormatAndPartition") = "YES"
Else
RemovePropertyIfPresent "doNotFormatAndPartition"
End if
RemovePropertyIfPresent "UserDataLocation"
RemovePropertyIfPresent "DestinationOSInstallType"
RemovePropertyIfPresent "DestinationOSVariable"
RemovePropertyIfPresent "OSDisk"
RemovePropertyIfPresent "OSDWinPEWindir"
RemovePropertyIfPresent "OriginalArchitecture"
ElseIf UDRadio2.Checked then
oLogging.CreateEntry "Migrate!", LogTypeInfo
KeepPartitions.Disabled = true
oProperties("doNotFormatAndPartition") = "YES"
oProperties("UserDataLocation") = "AUTO"
oProperties("DestinationOSInstallType") = "ByVariable"
oProperties("DestinationOSVariable") = "OSDisk"
oProperties("OSDisk") = g_OSDrive
If oFSO.FolderExists(g_OSDrive & "\Windows") then
oProperties("OSDWinPEWindir") = g_OSDrive & "\Windows"
ElseIf oFSO.FolderExists(g_OSDrive & "\Winnt") then
oProperties("OSDWinPEWindir") = g_OSDrive & "\Winnt"
End if
If oFSO.FolderExists(g_OSDrive & "\Program Files (x86)") then
oProperties("OriginalArchitecture") = "X64"
Else
oProperties("OriginalArchitecture") = "X86"
End if
End if
ValidateOfflineData = true
End Function