elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [APORTE] [BATCH] WIM Package Uninstaller
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] [BATCH] WIM Package Uninstaller  (Leído 3,223 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.878



Ver Perfil
[APORTE] [BATCH] WIM Package Uninstaller
« en: 14 Abril 2014, 05:50 am »

Este Script sirve para automatizar la tarea de montar una imagen WIM de Windows y eliminar paquetes de la instalación de Windows.

Se necesitan unos requisitos y dependencias para usar este Script:
· Saber de lo que estoy hablando.
· Conocer el nombre de los paquetes que quieres elimiar (obviamente).
· Dism e ImageX (WAIK/WADK).
· win6x_registry_tweak > http://www.msfn.org/board/topic/152688-win6x-registry-tweak/


Las instrucciones de uso y un extenso tutorial lo publiqué en este otro tema: http://foro.elhacker.net/windows/guia_de_personalizacion_de_imagenes_de_implementacion_de_windows_wim_parte_5-t412551.0.html así que lo haré de nuevo de manera resumida: solo tienen que escribir en un archivo de texto los paquetes que quieren eliminar, y configurar las variables documentadas del Script (La ubicación de la imagen, el directorio de montaje, etc...)


Todo lo necesario está incluido en este archivo comprimido:
http://www.mediafire.com/download/mq7o7q7brq6h4ca/WIM_Package_Uninstaller.rar

Imágenes:



WIM Package Uninstaller.cmd
Código
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title WIM Package Uninstaller - By Elektro
  10. Mode Con Cols=150 Lines=50
  11. CHCP 1252 1>NUL & REM Windows-1252, Spanish-Latin.
  12.  
  13.  
  14.  
  15. REM =====
  16. REM Info:
  17. REM =====
  18.  
  19. Echo  ----------------------------------------------------------------------------------
  20. Echo  This script mounts a Windows Image ^(WIM^) and then removes pre-installed packages
  21. Echo  ----------------------------------------------------------------------------------
  22.  
  23.  
  24.  
  25. REM ====================
  26. REM User defined values:
  27. REM ====================
  28.  
  29. REM This value indicates whether the Windows Image should be mounted.
  30. REM True  = 'DISM' will try to mount the 'WIM' image.
  31. REM False = 'DISM' will not try to mount the WIM image.
  32. REM Set this value to 'FALSE' if the 'WIM' image is already mounted in the specified mount directory,
  33. REM Otherwise, keep it as 'TRUE'.
  34. Set "MountImage=True"
  35.  
  36. REM This value indicates whether the Windows Image should be unmounted at the end.
  37. REM True  = 'DISM' will try to unmount the 'WIM' image.
  38. REM False = 'DISM' will not try to unmount the WIM image.
  39. REM Set this value to 'FALSE' if you want to keep the image mounted to make other changes,
  40. REM Otherwise, keep it as 'TRUE'.
  41. Set "UnmountImage=True"
  42.  
  43. REM This value indicates whether the Windows Image should be rebuilt at the end.
  44. REM True  = 'ImageX' will try to rebuild the 'WIM' image.
  45. REM False = 'ImageX' will keep the 'WIM' image as is.
  46. REM Set this value to 'FALSE' if you want to keep the image with normal size to make other changes,
  47. REM Otherwise, keep it as 'TRUE'.
  48. Set "Rebuild=True"
  49.  
  50. REM This value indicates the 'WIM' image to be mounted.
  51. Set "WindowsImage=%UserProfile%\Desktop\win 8 .1\win\sources\install.wim"
  52.  
  53. REM This value indicates the Image Index of the 'WIM' image.
  54. Set "ImageIndex=1"
  55.  
  56. REM This value indicates the directory where to mount the 'WIM' image.
  57. Set "MountDir=%HomeDrive%\WinMount"
  58.  
  59. REM This value indicates the textfile that contains the names of the packages to remove.
  60. Set "PackageList=%CD%\Packages.txt"
  61.  
  62. REM This value indicates the ubication of the 'WIM Registry Tweak Tool.exe' file.
  63. Set "WIMRegistryTweakTool=%CD%\Tools\WIM Registry Tweak Tool\WIM Registry Tweak Tool.exe"
  64.  
  65. REM This value indicates the ubication of 'ImageX.exe' file.
  66. Set "ImageX=%CD%\Tools\Dism\ImageX.exe"
  67.  
  68. REM This value indicates the ubication of a custom 'DISM.exe' file if needed.
  69. REM Default ubication: "%SystemRoot%\System32\Dism.exe"
  70. Set "Dism=%CD%\Tools\Dism\Dism.exe"
  71.  
  72. REM This value indicates the ubication of the logfile that will record 'DISM' errors.
  73. Set "DismLogfile=%CD%\%~n0 DISM.log"
  74.  
  75. REM This value indicates the logging-level of the 'DISM' process.
  76. REM 1 = Errors only
  77. REM 2 = Errors and warnings
  78. REM 3 = Errors, warnings, and informational
  79. REM 4 = All of the information listed previously, plus debug output
  80. Set /A "DismLogLevel=2"
  81.  
  82. REM This value indicates the ubication of the logfile that will record Main information.
  83. Set "Logfile=%CD%\%~n0.log"
  84.  
  85.  
  86.  
  87. REM =====
  88. REM Main:
  89. REM =====
  90.  
  91. :: Call Methods.
  92. Call :CheckErrors
  93. Call :CreateLogs
  94. Call :CreateMountDir
  95. Call :GetWIMSizeBefore
  96. Call :StartTimer
  97. Call :Mount
  98. CLS
  99. Call :ParsePackages
  100. CLS
  101. Call :CleanUp
  102. Call :Unmount
  103. Call :Rebuild
  104. Call :StopTimer
  105. Call :GetWIMSizeAfter
  106. Call :EndLog
  107. Pause&Exit
  108.  
  109.  
  110.  
  111. REM ========
  112. REM Methods:
  113. REM ========
  114.  
  115.  
  116. :CreateLogs
  117.  
  118. :: Create the 'DISM' logfile with 'ANSI' encoding,
  119. :: this is necessary to record a non-default 'DISM' loglevel such as '1' or '2'.
  120. Echo+ >"%DismLogfile%"
  121.  
  122.  
  123. :: Create the Main logfile and record starting info on it.
  124. Echo+ >"%Logfile%"
  125. (
  126. Echo   WIM Package Uninstaller
  127. Echo ===========================
  128. Echo   %DATE% ^| %TIME:~0,-3%
  129. Echo /\/\/\/\/\/\/\/\/\/\/\/\/\/
  130. Echo [i] Mount Image?...: %MountImage%
  131. Echo [i] Unmount Image?.: %UnmountImage%
  132. Echo [i] Windows Image..: %WindowsImage%
  133. Echo [i] Image Index....: %ImageIndex%
  134. Echo [i] Mount Directory: %MountDir%
  135. Echo [i] ImageX Path....: %ImageX%
  136. Echo [i] Dism Path......: %Dism%
  137. Echo [i] Dism Log File..: %DismLogfile%
  138. Echo [i] Dism Log Level.: %DismLogLevel%
  139. Echo [i] WIMRegistryTool: %WIMRegistryTweakTool%
  140. Echo [i] Package List...: %PackageList%
  141. Echo [i] Log File.......: %Logfile%
  142. Echo ===========================
  143. )>"%Logfile%"
  144.  
  145. :: Display starting log info.
  146. Type "%Logfile%"
  147.  
  148. :: Continue writting log.
  149. (
  150. Echo Package conflicts:
  151. Echo ==================
  152. )>>"%LogFile%"
  153. Goto:EOF
  154.  
  155.  
  156. :EndLog
  157. (
  158. Echo [i] Done!
  159. Echo [i] WIM Image Size Before........: %WIMSizeBefore%
  160. Echo [i] WIM Image Size After.........: %WIMSizeAfter%
  161. Echo [i] Packages Successfully Removed: %PackagesRemovedCount% Packages.
  162. Echo [i] Packages Failed To Remove....: %PackagesFailedCount% Packages.
  163. Echo [i] Packages Not Found...........: %PackagesNotFoundCount% Packages.
  164. Echo [i] Elapsed Time.................: %ElapsedTime%
  165. )>>"%LogFile%"
  166.  
  167. :: Display ending information.
  168. CLS
  169. Type "%LogFile%"
  170. Goto:EOF
  171.  
  172.  
  173. :CreateMountDir
  174. :: Create the mount directory.
  175. (
  176. If Not Exist "%MountDir%" If /I "%MountImage%" EQU "True" (
  177. MkDir "%MountDir%" 2>NUL
  178. )
  179. ) || (
  180. Echo [x] Error trying to create the directory "%MountDir%" to mount the Windows Image.
  181. Echo [i] Ensure that you have Admin rights to create the directory.
  182. Echo [i] Ensure that the directory name does not contains illegal characters.
  183. Pause&Exit
  184. )
  185. Goto:EOF
  186.  
  187.  
  188. :Mount
  189. :: Mount the Windows Image into the directory.
  190. Echo [+] Mounting WIM Image...
  191. If /I "%MountImage%" EQU "True" (
  192.  
  193. "%Dism%" /Mount-Image /ImageFile:"%WindowsImage%" /Index:"%ImageIndex%" /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" || (
  194. Echo [x] Error mounting the Image Index "%ImageIndex%" in "%MountDir%"
  195. Echo [i] Ensure that the Image Index exist.
  196. Echo [i] Ensure that you have Admin rights to write inside the directory.
  197. Echo [i] Ensure that the directory is not already mounted.
  198. Echo [i] Ensure that the directory is fully empty.
  199. REM Try to unmount the failed image and discard changes.
  200. If /I "%UnmountImage%" EQU "True" (
  201. Echo [+] Unmounting and discarding changes...
  202. "%Dism%" /Unmount-WIM /Discard /MountDir:"%MountDir%"
  203. )
  204. Pause&Exit
  205. )
  206.  
  207. )
  208. Goto:EOF
  209.  
  210.  
  211. :CleanUp
  212. Echo [+] CleaningUp WIM Image...
  213. "%Dism%" /CleanUp-Image /StartComponentCleanUp /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet
  214. Goto:EOF
  215.  
  216.  
  217. :Unmount
  218. :: Unmount the Windows Image commiting changes.
  219. Echo [+] Unmounting WIM Image...
  220. If /I "%UnmountImage%" EQU "True" (
  221. "%Dism%" /Unmount-WIM /Commit /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%"
  222. )
  223. Goto:EOF
  224.  
  225.  
  226. :Rebuild
  227. If /I "%Rebuild%" EQU "False" (Goto:EOF)
  228.  
  229. Echo [+] Rebuilding WIM image...
  230.  
  231. ("%ImageX%" /Compress Maximum /Export "%WindowsImage%" "*" "%TEMP%\Rebuilt Image.wim" /Check) && (
  232. Del /Q /F "%WindowsImage%" 1>NUL
  233. Move /Y "%TEMP%\Rebuilt Image.wim" "%WindowsImage%" 1>NUL
  234. ) || (
  235. Echo [x] Error rebuilding Image "%WindowsImage%" to "%TEMP%\Rebuilt Image.wim".
  236. )
  237.  
  238. Goto :EOF
  239.  
  240.  
  241. :StartTimer
  242. Set "StartingDate=%Date%"
  243. Set "StarttingTime=%Time:~0,-3%"
  244. Goto :EOF
  245.  
  246.  
  247. :StopTimer
  248. (
  249. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  250. Echo WScript.Echo Minutes ^& " Minutes"
  251. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  252.  
  253. For /F "Tokens=*" %%# In (
  254. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  255. ) Do (
  256. Set "ElapsedTime=%%#"
  257. )
  258.  
  259. Goto:EOF
  260.  
  261.  
  262. :WriteConvertBytesScript
  263. If Exist "%TEMP%\%~n0 Convert Bytes.vbs" (Goto:EOF)
  264. (
  265. Echo Suffix = Array^("Bytes", "KB", "MB", "GB", "TB"^)
  266. Echo Function Convert^(Bytes^)
  267. Echo Convert = convert0^(Bytes, 0^)
  268. Echo End Function
  269. Echo Function Convert0^(Bytes, Level^)
  270. Echo If Bytes ^>= 1024 Then
  271. Echo Bytes = Round^(Bytes / 1024, 2^)
  272. Echo Level = Level + 1
  273. Echo Convert0 = Convert0^(Bytes, Level^)
  274. Echo End If
  275. Echo Convert0 = Bytes ^& " " ^& Suffix^(Level^)
  276. Echo End Function
  277. Echo WScript.Echo Convert^(WScript.Arguments^(0^)^)
  278. )>"%TEMP%\%~n0 Convert Bytes.vbs"
  279. Goto:EOF
  280.  
  281.  
  282. :GetWIMSizeBefore
  283. Call :WriteConvertBytesScript
  284. For %%# in ("%WindowsImage%") Do (Set "WIMSizeBefore=%%~z#")
  285. For /F "Tokens=*" %%# In (
  286. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeBefore%"'
  287. ) Do (
  288. Set "WIMSizeBefore=%%#"
  289. )
  290. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  291. Goto:EOF
  292.  
  293.  
  294. :GetWIMSizeAfter
  295. Call :WriteConvertBytesScript
  296. For %%# in ("%WindowsImage%") Do (Set "WIMSizeAfter=%%~z#")
  297. For /F "Tokens=*" %%# In (
  298. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeAfter%"'
  299. ) Do (
  300. Set "WIMSizeAfter=%%#"
  301. )
  302. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  303. Goto:EOF
  304.  
  305.  
  306. :ParsePackages
  307.  
  308. Set /A "PackagesRemovedCount=0"
  309. Set /A "PackagesFailedCount=0"
  310. Set /A "PackagesNotFoundCount=0"
  311.  
  312. :: Unhide packages and take registry ownership.
  313. "%WIMRegistryTweakTool%" /p "%MountDir%"
  314.  
  315. :: Remove Packages.
  316. For /F "UseBackQ Tokens=* Delims=" %%# In ("%PackageList%") Do (
  317.  
  318. Echo [+] Removing package: %%~#
  319.  
  320. "%Dism%" /Remove-Package /PackageName:"%%~#" /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet 1>NUL
  321.    Call Set /A "ExitCode=%%Errorlevel%%"
  322.  
  323.    (Call Echo "%%ExitCode%%"| Findstr.exe "^\"0\"$" 1>NUL 2>&1) && (
  324.     Call Set /A "PackagesRemovedCount+=1"
  325.    )
  326.  
  327. (Call Echo "%%ExitCode%%"| Findstr.exe "^\"5\"$" 1>NUL 2>&1) && (
  328. Call Set /A "PackagesFailedCount+=1"
  329. Echo Failed to remove package: %%~#>>"%LogFile%"
  330. )
  331.  
  332. (Call Echo "%%ExitCode%%"| Find.exe "-2146498555" 1>NUL 2>&1) && (
  333. Call Set /A "PackagesNotFoundCount+=1"
  334. Echo Package is not installed: %%~#>>"%LogFile%"
  335. )
  336.  
  337. )
  338. Goto:EOF
  339.  
  340.  
  341.  
  342. REM ===============
  343. REM Error Controls:
  344. REM ===============
  345.  
  346. :CheckErrors
  347. :: WIM File Error-Check.
  348. If /I "MountImage" EQU "True" If Not Exist "%WindowsImage%" (
  349. Echo [x] Windows Image not found at: "%WindowsImage%" | MORE
  350. Pause&Exit
  351. )
  352.  
  353. :: PackageList File Error-Check.
  354. If Not Exist "%PackageList%" (
  355. Echo [x] PackageList not found at: "%PackageList%" | MORE
  356. Pause&Exit
  357. )
  358.  
  359. :: 'DISM.exe' File Error-Check.
  360. If Not Exist "%DISM%" (
  361. Echo [x] 'DISM' process not found at: "%DISM%" | MORE
  362. Pause&Exit
  363. )
  364.  
  365. :: 'ImageX.exe' File Error-Check.
  366. If Not Exist "%ImageX%" (
  367. Echo [x] 'ImageX' process not found at: "%ImageX%" | MORE
  368. Pause&Exit
  369. )
  370.  
  371. :: 'WIM Registry Tweak Tool.exe' File Error-Check.
  372. If Not Exist "%WIMRegistryTweakTool%" (
  373. Echo [x] 'WIM Registry Tweak Tool' process not found at: "%WIMRegistryTweakTool%" | MORE
  374. Pause&Exit
  375. )
  376.  
  377. :: 'MountImage' Value check.
  378. If /I "%MountImage%" NEQ "True" If /I "%MountImage%" NEQ "False" (
  379. Echo [x] Error parsing parameter 'MountImage',
  380. Echo     value '%MountImage%' is not a Boolean value.
  381. Pause&Exit
  382. )
  383.  
  384. :: 'UnmountImage' Value check.
  385. If /I "%UnmountImage%" NEQ "True" If /I "%UnmountImage%" NEQ "False" (
  386. Echo [x] Error parsing parameter 'UnmountImage',
  387. Echo     value '%UnmountImage%' is not a Boolean value.
  388. Pause&Exit
  389. )
  390.  
  391. :: 'Rebuild' Value check.
  392. If /I "%Rebuild%" NEQ "True" If /I "%Rebuild%" NEQ "False" (
  393. Echo [x] Error parsing parameter 'Rebuild',
  394. Echo     value '%Rebuild%' is not a Boolean value.
  395. Pause&Exit
  396. )
  397.  
  398. :: 'DismLogLevel' Value check.
  399. Echo "%DismLogLevel%"| Findstr.exe "^\"[^1-4]\"$" 1>NUL 2>&1 || (
  400. Echo [x] Error parsing parameter 'DismLogLevel',
  401. Echo     value '%DismLogLevel%' is not in range '1-4'.
  402. Pause&Exit
  403. )
  404.  
  405. Goto:EOF


En línea



Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines