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

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


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

Mensajes: 9.866



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

Este Script sirve para automatizar la tarea de montar una imagen WIM de Windows y desactivar características 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 las características que quieres elimiar (obviamente).
· Dism e ImageX (WAIK/WADK).


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 el nombre de las características que quieren desactivar, 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/lq4sc56ri59klod/WIM_Feature_Uninstaller.rar


Imágenes:



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