-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStep2.cmd
230 lines (189 loc) · 9.79 KB
/
Step2.cmd
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
REM After reboot (TWICE!!! for chkdsk to finish?) run this script to sysprep
@echo off
echo Turn off hibernate...
powercfg /H off
rem remove firstboot profile
echo removing firstboot profile...
wmic /node:localhost path win32_UserProfile where LocalPath="c:\\users\\firstboot" Delete 2>>%windir%\setup\sysprep_scripts\wmic.err
rem delete shadow copies
echo deleting shadow copies...
vssadmin delete shadows /All /Quiet
rem Delete hidden win install files
rem echo clearing win install files...
rem del %windir%\$NT* /f /s /q /a:h
rem remove windows prefetch files
rem del c:\Windows\Prefetch\*.* /f /s /q
del /F c:\windows\system32\sysprep\panther\setupact.log
del /F c:\windows\system32\sysprep\panther\setuperr.log
del /F c:\windows\system32\sysprep\panther\ie\setupact.log
del /F c:\windows\system32\sysprep\panther\ie\setuperr.log
del /F /Q c:\windows\system32\sysprep\panther\*
echo disabling FOGService during sysprep...
rem turn off fog service during clone
net stop FOGService
sc config FOGService start=disabled
del /F "C:\Program Files (x86)\FOG\fog.log"
del /F "C:\fog.log"
del /F "C:\Program Files (x86)\FOG\token.dat"
rem -- CLEAR TEMP FOLDERS --
echo Do you want to cleanup temp folders [recommended - default N in 6 seconds]?
choice /C yn /T 6 /D n /M "Press y for yes, or n to skip"
if errorlevel 2 goto skipcleartempfolders
echo Clearing temp folders...
echo -- Clearing Oculus Staging folder...
rd "C:\Program Files\Oculus\Staging\" /Q /S > nul
echo -- Clearing out Windows\Installer folder with patch cleaner...
"C:\Program Files (x86)\HomeDev\PatchCleaner\PatchCleaner.exe" /d
echo -- Running Dism to clean up winsxs folder...
Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
Dism.exe /online /Cleanup-Image /SPSuperseded
:skipcleartempfolders
echo Do you want to run disk cleanup [recommended - default N in 6 seconds]?
choice /C yn /T 6 /D n /M "Press y for yes, or n to skip"
if errorlevel 2 goto skipdiskcleanup
echo running disk cleanup...
cleanmgr /sagerun:1
:skipdiskcleanup
echo Do you want to zero the drive [recommended but takes hours - default N in 6 seconds]?
choice /C yn /T 6 /D n /M "Press y for yes, or n to skip"
if errorlevel 2 goto skipzero
echo Writing zeros to the drive...
rem c:\windows\setup\sysprep_scripts\sdelete\sdelete -z c:
:skipzero
echo Do you want to run defrag [recommended]?
choice /C yn /T 6 /D n /m "Press n for no, or y to run defrag - default N in 6 seconds"
if errorlevel 2 goto skipdefrag
defrag c: /U /V
:skipdefrag
REM enable the firstboot user if it exists so it can autologin
rem echo "enabling firstboot account..."
rem NET USER firstboot /active:yes
rem set startup script
rem wmic /node:localhost path win32_NetworkLoginProfile where caption="firstboot" set scriptpath="c:\apps\sysprep_scripts\SetupComplete.cmd"
REM NOTE: This will run for ANY user that logs in, so the firstboot user doesn't need a startup script, just be set to login.
rem reg add HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce /v SetupComplete /t REG_SZ /d "c:\apps\sysprep_scripts\SetupComplete.cmd reboot" /f
rem reg add HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce /v SetupComplete /t REG_SZ /d "c:\apps\sysprep_scripts\SetupComplete.cmd" /f
rem disable cortana
rem reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Windows Search" /v AllowCortana /t REG_DWORD /d 0 /f
rem Export current app defaults so we can import them later
DISM /online /export-defaultappassociations:%windir%\setup\sysprep_scripts\AppAssoc.xml
REM PC software - use these keys for win 10 pro and office 2016
REM Install public KMS keys for auto activation
cscript c:\windows\system32\slmgr.vbs /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
cscript "c:\Program Files\Microsoft Office\Office16\ospp.vbs" /inpkey:XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99
REM ---------- SCRATCH -------------------
rem win 10 pro - W269N-WFGWX-YVC9B-4J6C9-T83GX
rem win 10 enterprise - NPPR9-FWDCX-D2C8J-H872K-2YT43
rem activate with kms server
REM c:\windows\system32\slmgr.vbs /ato
rem view detailed info
rem slmgr.vbs /dlv
rem enable auto discovery of kms server
rem slmgr.vbs /ckms
rem manual activation
rem slmgr.vbs /skms server:port
REM set APP=sysinternalssuite\psexec.exe
REM set LIST=computer_list_test.txt
REM set LIST=computer_list.txt
REM active win 10
REM %APP% @%LIST% -dehs cmd /C "cscript 'c:\windows\system32\slmgr.vbs' /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX"
REM %APP% @%LIST% -dehs cmd /C "cscript 'c:\windows\system32\slmgr.vbs' /ato"
REM activate office
REM %APP% @%LIST% -dehs cmd /C "cscript 'c:\Program Files\Microsoft Office\Office16\ospp.vbs' /inpkey:XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99"
REM %APP% @%LIST% -dehs cmd /C "cscript 'c:\Program Files\Microsoft Office\Office16\ospp.vbs' /act"
rem activate office 2016 with KMS server
rem CD \Program Files\Microsoft Office\Office16
rem specify server name
rem cscript ospp.vbs /sethst:kms01.yourdomain.com
REM set public kms key for office 2016
rem .\psexec.exe \\acct-inst,acct-1,acct-2,acct-3,acct-4,acct-5,acct-ta1,acct-ta2 -u huskers -dehs cmd /C "cscript 'c:\Program Files\Microsoft Office\Office16\ospp.vbs' /inpkey:XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99"
rem activate office
REM REM cscript c:\Program Files\Microsoft Office\Office16\ospp.vbs /act
rem status of activation
rem cscript ospp.vbs /dstatusall
rem disable host cache
rem cscript ospp.vbs /cachst:FALSE
rem enable host cache
rem cscript ospp.vbs /cachst:TRUE
rem --- kms notes - activate kms host - activate initial host requires internet or phone ---
rem Check current status
rem slmgr.vbs /dlv
rem uninstall current kms key
rem slmgr.vbs /upk
rem install new KMS key
rem slmgr.vbs /ipk KEY TO INSTALL
rem activate kms host
rem slmgr.vbs /ato
rem c:\windows\system32\slmgr.vbs
REM ---------- SCRATCH -------------------
rem allow win store apps to update again
REM reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\WindowsStore /v AutoDownload /f
REM Make sure we remove error entries from before
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\Sysprep" /v "SysprepCorrupt" /f
REM Set sysprep states properly
reg add "HKEY_LOCAL_MACHINE\System\Setup\Status\SysprepStatus" /v "CleanupState" /t REG_DWORD /d 2 /f
reg add "HKEY_LOCAL_MACHINE\System\Setup\Status\SysprepStatus" /v "GeneralizationState" /t REG_DWORD /d 2 /f
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\SoftwareProtectionPlatform" /v "SkipRearm" /t REG_DWORD /d 1 /f
REM reinstall mstdc
c:\windows\system32\msdtc.exe –uninstall
c:\windows\system32\msdtc.exe –install
REM Copy SetupComplete.cmd to c:\windows\setup\scripts\
echo Copying SetupComplete.cmd and ErrorHandler.cmd into c:\windows\setup\scripts folder...
c:\windows\system32\takeown.exe /f %windir%\setup 1>nul
c:\windows\system32\icacls.exe %windir%\setup /grant Administrators:(OI)(CI)F /T 1>nul
mkdir %windir%\setup\scripts
copy %~dp0\SetupComplete.cmd %windir%\setup\scripts\
copy %~dp0\ErrorHandler.cmd %windir%\setup\scripts\
echo -----------------------------------------------------------------
echo - NOTE - broken win 10 1709 - will fail on sysprep
echo - Edit c:\windows\system32\sysprep\actionfiles\generalize.xml
echo - Comment out whole section on Appx (from <image to </image> )
echo -----------------------------------------------------------------
echo Auto apply fix to generalize.xml?
choice /C yn /T 6 /D y /m "Press n for no, or y to auto fix - default to Y in 6 seconds"
if errorlevel 2 goto skipfixgeneralize
c:\windows\system32\takeown.exe /R /f %windir%\system32\sysprep\actionfiles
c:\windows\system32\icacls.exe %windir%\system32\sysprep\actionfiles /grant:r "Administrators:(OI)(CI)F" /T
c:\windows\system32\icacls.exe %windir%\system32\sysprep\actionfiles\Generalize.xml /grant:r "Administrators:F" /T
echo on
copy %~dp0\Generalize.xml %windir%\system32\sysprep\actionfiles\Generalize.xml
:skipfixgeneralize
echo
echo
echo "Clean windows store and store apps?"
echo
choice /C yn /T 6 /D y /m "Press n for no, or y to clean store apps - default Y in 6 seconds"
if errorlevel 2 goto skipcleanapps
rem PowerShell -Command "& {Get-AppxProvisionedPackage –online | Remove-AppxProvisionedPackage -online}"
PowerShell -Command "Get-AppxProvisionedPackage -Online | Remove-AppxProvisionedPackage -Online"
PowerShell -Command "Get-AppxPackage -AllUsers | Remove-AppxPackage"
:skipcleanapps
rem kill tasklist /svc /fi "services eq StateRepository"
net stop StateRepository
rem Make sure this folder is gone
c:\windows\system32\takeown.exe /R /f c:\windows\system32\inetsrv
c:\windows\system32\icacls.exe c:\windows\system32\inetsrv /grant:r "Administrators:(OI)(CI)F" /T
c:\windows\system32\icacls.exe c:\windows\system32\inetsrv /grant:r "Administrators:F" /T
rd /s /q c:\windows\system32\inetsrv
rem clean up app store apps
c:\windows\system32\takeown.exe /R /f "c:\program files\WindowsApps"
c:\windows\system32\icacls.exe "c:\program files\WindowsApps" /grant:r "Administrators:(OI)(CI)F" /T
c:\windows\system32\icacls.exe "c:\program files\WindowsApps" /grant:r "Administrators:F" /T
rd /s /q "c:\program files\WindowsApps"
c:\windows\system32\takeown.exe /R /f "c:\ProgramData\Microsoft\Windows\AppRepository"
c:\windows\system32\icacls.exe "c:\ProgramData\Microsoft\Windows\AppRepository" /grant:r "Administrators:(OI)(CI)F" /T
c:\windows\system32\icacls.exe "c:\ProgramData\Microsoft\Windows\AppRepository" /grant:r "Administrators:F" /T
net stop StateRepository
rd /s /q "c:\ProgramData\Microsoft\Windows\AppRepository"
echo
echo
echo "This will run sysprep and shutdown."
echo Do you want to run sysprep [recommended]?
choice /C yn /m "Press n for no, or y to run sysprep"
if errorlevel 2 goto skipsysprep
echo " DO NOT do anything during sysprep!!!"
echo " DO NOT start the machine back up - start your imaging process to capture after shutdown!!!"
rem get current path for the unattend.xml file
set upath=%~dp0unattend.xml
%windir%\system32\sysprep\sysprep.exe /oobe /generalize /shutdown /unattend:%upath%
:skipsysprep