· 9 years ago · Nov 09, 2016, 11:16 PM
1@echo off
2@rem This script is called by x:\Windows\System32\Startnet.cmd - WinPE
3@echo.
4@echo.
5@echo.
6@echo Running Intel Optimization powercfg for improved imaging times
7@echo.
8@echo call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
9call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
10@echo.
11@echo.
12@rem
13@rem This is the default product key being used:
14set productkey=37GNV-YCQVD-38XP9-T848R-FC2HD
15@rem
16@rem Home/Core: 37GNV-YCQVD-38XP9-T848R-FC2HD
17@rem Pro: NF6HC-QH89W-F8WYV-WWXV4-WFG6P
18@rem Enterprise: GN7FR-4QK4T-8XPDY-P2RYF-QGP4G
19@rem CHN SL: 7B6NC-V3438-TRQG7-8TCCX-H6DDY
20@rem SL: NTRHT-XTHTG-GBWCG-4MTMP-HH64C
21
22@echo.
23@rem *****************************************************************
24@rem List all the disks, then search the volumes of each one to see
25@rem which disks may have "Winpe" in the label. We will ignore that
26@rem disk and use the first disk without the Winpe label that we find.
27@rem *****************************************************************
28@echo.>x:\listdisk.txt
29@echo list disk>>x:\listdisk.txt
30@echo exit>>x:\listdisk.txt
31echo x:\listdisk.txt
32@echo call diskpart /s x:\listdisk.txt
33call diskpart /s x:\listdisk.txt>x:\Disks.txt
34@echo.
35@rem Set Disk equal to blank to start
36set disk=
37@echo.
38@rem
39@rem This line will write a diskpart script to select the disk and detail it's contents.
40@rem We use this output to find a disk that does NOT have Winpe as the volume label.
41@rem That disk will have the OS installed to it. This way you can exclude USB from diskpart.
42@rem
43@rem This works around the issue where the USB key is sometimes enumerated as disk 0 and the
44@rem SSD is disk 1.
45@rem
46for /f "skip=8 tokens=2" %%A in (x:\Disks.txt) do (
47@echo sel disk %%A>x:\Par.txt
48@echo det disk>>x:\Par.txt
49@echo exit>>x:\Par.txt
50if NOT "%%A"=="DiskPart..." call :ListPar %%A
51)
52if "%Disk%"=="" echo No disk found without a volume label of "Winpe"&& set disk=0
53@echo Using Disk "%Disk%"
54@echo.
55@echo.
56@echo.
57@rem *****************************************************************
58@rem Detect if System is booted into UEFI mode or Bios mode
59@rem *****************************************************************
60for /f "tokens=2* delims= " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') do set Firmware=%%B
61@echo.
62if %Firmware%==0x1 goto :Biosmode
63if %Firmware%==0x2 goto :UEFImode
64Goto :END
65:UEFImode
66@echo.
67@rem ************************
68@rem UEFI SECTION
69@rem ************************
70@echo The PC is booted in UEFI mode
71@echo.>x:\winpart.txt
72@echo select disk "%Disk%">>x:\winpart.txt
73@echo clean>>x:\winpart.txt
74@echo convert gpt>>x:\winpart.txt
75@echo create partition efi size=100>>x:\winpart.txt
76@echo format quick fs=fat32 label="System">>x:\winpart.txt
77@echo assign letter="S">>x:\winpart.txt
78@echo create partition msr size=16>>x:\winpart.txt
79@echo create partition primary>>x:\winpart.txt
80@echo format quick fs=ntfs label="Local Disk">>x:\winpart.txt
81@echo assign letter="W">>x:\winpart.txt
82@echo shrink desired=1000>>x:\winpart.txt
83@echo create partition primary>>x:\winpart.txt
84@echo format quick fs=ntfs label="Recovery">>x:\winpart.txt
85@echo assign letter="R">>x:\winpart.txt
86@echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac">>x:\winpart.txt
87@echo gpt attributes=0x8000000000000001>>x:\winpart.txt
88@echo exit>>x:\WinPart.txt
89Goto :WINPARTSECTION
90
91:Biosmode
92@rem ************************
93@rem BIOS SECTION
94@rem ************************
95@echo The PC is booted in BIOS mode
96@echo The PC is booted in BIOS mode>x:\Bios.txt
97@echo.>x:\winpart.txt
98@echo select disk "%Disk%">>x:\winpart.txt
99@echo clean>>x:\winpart.txt
100@echo create partition primary size=100>>x:\winpart.txt
101@echo active>>x:\winpart.txt
102@echo format quick fs=fat32 label="System">>x:\winpart.txt
103@echo assign letter="S">>x:\winpart.txt
104@echo create partition primary>>x:\winpart.txt
105@echo format quick fs=ntfs label="Windows">>x:\winpart.txt
106@echo assign letter="W">>x:\winpart.txt
107@echo exit>>x:\winpart.txt
108@echo.
109
110:WINPARTSECTION
111@echo Winpart.txt now contains.....
112@echo.
113type x:\winpart.txt
114@echo.
115@echo.
116@echo *****************************************************************
117@echo Setting up the partition table
118@echo *****************************************************************
119@echo call diskpart /s x:\winpart.txt
120diskpart /s x:\winpart.txt
121@echo.
122@echo.
123@echo *****************************************************************
124@rem Map drive letter for Install.wim
125@echo *****************************************************************
126@echo.>x:\ListVol.txt
127@echo List volume>>x:\ListVol.txt
128@echo exit>>x:\ListVol.txt
129@echo call diskpart /s x:\ListVol.txt
130call diskpart /s x:\ListVol.txt>x:\Output.txt
131@echo.
132@echo.
133@rem Go through each drive letter, looking for the images\Install.txt file
134for /f "skip=8 tokens=3" %%A in (x:\Output.txt) do (
135if exist %%A:\images\install.txt set InstallPath=%%A:\images&& echo "Found device with images folder and install.txt file"
136)
137@echo.
138@echo.
139@rem Check InstallPath was found and there are images in it.
140if NOT EXIST %InstallPath%\Install.wim echo "Install.wim NOT found." && goto :Error
141@echo Install.wim FOUND at %InstallPath%\images\install.wim
142@echo.
143@echo.
144@echo Making directories...
145md w:\recycler\scratch
146if %errorlevel% NEQ 0 echo "Failed to make w:\recycler\scratch directory" && goto :error
147@echo.
148md r:\recovery\windowsre
149if %errorlevel% NEQ 0 echo "Failed to make m:\recovery\windowsre directory" && goto :error
150@echo.
151@echo *****************************************************************
152@echo Applying the Windows image from the USB
153@echo *****************************************************************
154@echo call DISM /Apply-Image /ImageFile:%InstallPath%\install.wim /Index:1 /ApplyDir:w:\ /Compact /ScratchDir:w:\recycler\SCRATCH
155call DISM /Apply-Image /ImageFile:%InstallPath%\install.wim /Index:1 /ApplyDir:w:\ /Compact /ScratchDir:w:\recycler\SCRATCH
156if %errorlevel% NEQ 0 echo "Failed to apply image to w:" && goto :error
157@echo.
158@echo.
159@echo.
160@echo *****************************************************************
161@echo Add default product key
162@echo *****************************************************************
163@echo call DISM /Image:w: /Set-ProductKey:%productkey%
164call DISM /Image:w: /Set-ProductKey:%productkey%
165if %errorlevel% NEQ 0 echo "Failed to set productkey." && goto :error
166@echo.
167@echo.
168@echo.
169@echo *****************************************************************
170@rem Move WinRE to Recovery Partition
171@echo *****************************************************************
172@echo.
173@echo Modifying attributes of winre.wim so we can move it.
174attrib w:\Windows\System32\recovery\winre.wim -s -h -a -r
175@echo move w:\Windows\System32\recovery\winre.wim r:\recovery\windowsre
176move w:\Windows\System32\recovery\winre.wim r:\recovery\windowsre
177if %errorlevel% NEQ 0 echo "Failed to move winre.wim to r:\recovery\windowsre" && goto :error
178@echo.
179@echo reset attributes now
180attrib r:\Recovery\Windowsre\winre.wim +s +h +a +r
181@echo.
182@echo.
183@echo *****************************************************************
184@echo Setting the boot environment
185@echo *****************************************************************
186@echo call w:\WINDOWS\SYSTEM32\BCDBOOT w:\WINDOWS /s s: /f all
187w:\WINDOWS\SYSTEM32\BCDBOOT w:\WINDOWS /s s: /f all
188if %errorlevel% NEQ 0 echo "Failed to set boot information" && goto :error
189@echo.
190@echo.
191@echo.
192@echo *****************************************************************
193@echo Setting the recovery environment
194@echo *****************************************************************
195@echo w:\windows\system32\reagentc /SetREImage /Path r:\RECOVERY\WINDOWSRE /target w:\windows
196w:\windows\system32\reagentc /SetREImage /Path r:\RECOVERY\WINDOWSRE /target w:\windows
197if %errorlevel% NEQ 0 echo "Failed to set recovery information" && goto :error
198@echo.
199@echo.
200@echo.
201@echo *****************************************************************
202@echo Copying over Unattend.xml to use on factory floor if it exists
203@echo *****************************************************************
204@echo if EXIST %WinPESource%Scripts\Unattend.xml copy %WinPESource%Scripts\Unattend.xml w:\Windows\Panther /y
205if EXIST %WinPESource%Scripts\Unattend.xml copy %WinPESource%Scripts\Unattend.xml w:\Windows\Panther /y
206@echo.
207@echo *****************************************************************
208@echo Copying over NON Scanstate Packages, if they exist.
209@echo IF YOU COPY OVER SCANSTATE PPKG, THIS CAUSE IMAGE TO FAIL DURING RECOVERY
210@echo *****************************************************************
211@echo if EXIST %WinPESource%Scripts\*.ppkg copy %WinPESource%Scripts\*.ppkg r:\Recovery\Customizations /y
212if EXIST %WinPESource%Scripts\*.ppkg copy %WinPESource%Scripts\*.ppkg r:\Recovery\Customizations /y
213@echo.
214@echo *****************************************************************
215@echo Copying over resetconfig.xml and assets, if they exist.
216@echo *****************************************************************
217@echo if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\Recovery\*.* w:\Recovery /e /y
218if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\Recovery\*.* w:\Recovery /e /y
219@echo.
220@echo.
221@echo.
222@echo.
223@echo *****************************************************************
224@echo Copying over tool, if they exist.
225@echo *****************************************************************
226@echo if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\TEST_TOOL\*.* w:\ /e /y
227if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\TEST_TOOL\*.* w:\ /e /y
228@echo.
229@echo.
230@echo.
231@echo *****************************************************************
232@echo Copying over test, if they exist.
233@echo *****************************************************************
234@echo if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\desktop\*.* w:\Users\Administrator\Desktop /e /y
235if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\desktop\*.* w:\Users\Administrator\Desktop /e /y
236@echo.
237@echo.
238@echo *****************************************************************
239@echo.
240@echo.
241@echo *****************************************************************
242@echo Image deployment COMPLETE. Type EXIT from Command
243@echo Prompt to restart or turn off device.
244@echo *****************************************************************
245goto :END
246
247:ERROR
248@echo.
249@echo An error has been detected.
250@echo.
251goto :END
252
253:ListPar
254@REM This section is to bring a disk number and use it to List Partitions
255@echo.
256set TempDisk=%1
257diskpart /s x:\Par.txt>x:\ParOutput.txt
258for /f "skip=26 tokens=4" %%A in (x:\ParOutput.txt) do (
259if /i NOT "%%A"=="Winpe" set Disk=%TempDisk%
260)
261Goto :EOF
262
263:END
264@rem
265@rem Get finish time so we can evaluate total WinPE phase time.
266@rem
267call |time>x:\StopTime.txt
268@rem
269@rem Now parse both files to display the Start and Finish Time
270@rem
271@echo.
272@echo.
273for /f "tokens=5" %%A in (x:\starttime.txt) do echo Script Start Time is %%A
274for /f "tokens=5" %%A in (x:\stoptime.txt) do echo Script Stop Time is %%A
275@echo.
276exit