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

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Mensajes
Páginas: 1 ... 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 [714] 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 ... 1236
7131  Programación / Scripting / [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
7132  Programación / Scripting / [APORTE] [BATCH] Filesize Truncator en: 14 Abril 2014, 05:01 am
Filesize Truncator

Este Script trunca el tamaño de los archivos que estén en el directorio de trabajo actual y en sus subdirectorios.
Nota: El directorio y otras propiedades se pueden modificar en las variables documentadas del código.

En realidad lo que hace es eliminar permanentemente el archivo, y luego se crea un archivo de 0 bytes con el mismo nombre y en la misma ubicación que el que se borró.

Esto es util por ejemplo si necesitamos crear una estructura de carpetas y archivos pero estos pesan demasiado tamaño y solo necesitamos mantener los nombres de los archivos y sus ubicaciones...

El Script tiene 2 métodos de búsqueda de archivos, el modo normal y el modo que incluye archivos ocultos.

Imágenes:




Source:
Código
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title Filesize Truncator - 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 will truncate to Zero the size of the files inside the working directory and it's subdirectories
  21. Echo  ------------------------------------------------------------------------------------------------------------
  22. Echo  Take extreme caution, truncating the filesize has the same effect as deleting the file !!
  23. Echo  -----------------------------------------------------------------------------------------
  24.  
  25.  
  26.  
  27. REM ====================
  28. REM User defined values:
  29. REM ====================
  30.  
  31. REM This value indicates the directory where to list it's file structure.
  32. Set "WorkingDir=%CD%"
  33.  
  34. REM This value indicates the ubication of the logfile that will record info.
  35. Set "Logfile=%CD%\%~n0.log"
  36.  
  37. REM This value indicates the File-Extensions to exclude during the process.
  38. REM ( Use an ';' delimiter to separate multiple extensions )
  39. Set "ExcludeExts=.bat;.cmd"
  40.  
  41. REM This value indicates the filenames to exclude during the process.
  42. REM ( Use an ';' delimiter to separate multiple filenames )
  43. Set "ExcludeNames=%~nx0;Files.txt;Files2List.log"
  44.  
  45. REM This value indicates the files to exclude during the process.
  46. REM ( Use an ';' delimiter to separate multiple files )
  47. Set "ExcludeFiles=%Logfile%"
  48.  
  49. REM This value indicates how the hidden files are threated when listing the file structure.
  50. REM  True = List files and also files with the 'hidden' attribute.
  51. REM False = List only normal files without the 'hidden' attribute.
  52. Set "IncludeHiddenFiles=True"
  53.  
  54.  
  55.  
  56. REM =====
  57. REM Main:
  58. REM =====
  59.  
  60. :: Warning question.
  61. Call :CreateLog
  62. Choice /C "YN" /M "This will delete the files, you want to continue?"
  63. If %ErrorLevel% NEQ 1 (Exit)
  64.  
  65. :: Call Methods.
  66. Call :CheckErrors
  67. Call :StartTimer
  68. Call :TruncateFiles "%IncludeHiddenFiles%"
  69. Call :StopTimer
  70. Call :EndLog
  71. Pause&Exit
  72.  
  73.  
  74.  
  75. REM ========
  76. REM Methods:
  77. REM ========
  78.  
  79. :CreateLog
  80. :: Create the Script Logfile and record starting info on it.
  81. FSutil.exe File CreateNew "%LogFile%" "0" 1>NUL
  82. (
  83. Echo    Filesize Truncator
  84. Echo =========================
  85. Echo   %DATE% ^| %TIME:~0,-3%
  86. Echo /\/\/\/\/\/\/\/\/\/\/\/\/
  87. Echo [i] Working Directory...: %WorkingDir%
  88. Echo [i] Include Hidden Files: %IncludeHiddenFiles%
  89. Echo [i] Excluded Extensions.: %ExcludeExts%
  90. Echo [i] Excluded Filenames..: %ExcludeNames%
  91. Echo [i] Excluded Files......: %ExcludeFiles%
  92. Echo [i] Log file............: %LogFile%
  93. Echo =========================
  94. )>"%LogFile%"
  95.  
  96. :: Display starting log info.
  97. Type "%LogFile%" | MORE
  98.  
  99. :: Continue writting log.
  100. (
  101. Echo Excluded Files:
  102. Echo ===============
  103. )>>"%LogFile%"
  104.  
  105. Goto:EOF
  106.  
  107.  
  108. :EndLog
  109. (
  110. Echo [i] Done!
  111. Echo [i] Truncated Files: %TruncatedFileCount% files.
  112. Echo [i] Excluded Files.: %ExcludedFileCount% files.
  113. Echo [i] Elapsed Time...: %ElapsedTime%
  114. )>>"%LogFile%"
  115.  
  116. :: Display ending information.
  117. CLS
  118. Type "%LogFile%"
  119. Goto:EOF
  120.  
  121.  
  122. :StartTimer
  123. Set "StartingDate=%Date%"
  124. Set "StarttingTime=%Time:~0,-3%"
  125. Goto :EOF
  126.  
  127.  
  128. :StopTimer
  129. (
  130. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  131. Echo WScript.Echo Minutes ^& " Minutes"
  132. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  133.  
  134. For /F "Tokens=*" %%# In (
  135. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  136. ) Do (
  137. Set "ElapsedTime=%%#"
  138. )
  139.  
  140. Goto:EOF
  141.  
  142.  
  143. :TakeOwn
  144. (
  145. Takeown.exe /F "%~f1"
  146. ICacls.exe "%~f1" /Grant "%UserName%":"F"
  147. Attrib.exe -R -A -S -H -I "%~f1"
  148. )>NUL || (Exit /B 1)
  149. Goto:EOF
  150.  
  151.  
  152. :TruncateFiles
  153. Echo [+] Truncating files with size greater than Zero, this operation could take some minutes long, please wait...
  154. If /I "%~1" EQU "True"  (Call :TruncateHiddenFiles)
  155. If /I "%~1" EQU "False" (Call :TruncateNormalFiles)
  156. Goto:EOF
  157.  
  158.  
  159. :TruncateNormalFiles
  160. FOR /R "%WorkingDir%" %%# in ("*") DO (
  161.  
  162. If %%~z# NEQ 0 (
  163.  
  164. Set "Exclude="
  165.  
  166. If Defined ExcludeExts (
  167. (
  168. Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  169. ) && (
  170. Call Set "Exclude=True"
  171. )
  172. )
  173.  
  174. If Defined ExcludeNames (
  175. (
  176. Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  177. ) && (
  178. Call Set "Exclude=True"
  179. )
  180. )
  181.  
  182. If Defined ExcludeFiles (
  183. (
  184. Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  185. ) && (
  186. Call Set "Exclude=True"
  187. )
  188. )
  189.  
  190. If Not Defined Exclude (
  191. Set "File=%%~f#"
  192. Call Echo [.] Truncating: %%File:%WorkingDir%=.%%
  193. Call :TakeOwn "%%~f#"
  194. Del /Q "%%~f#"
  195. FSUtil.exe File CreateNew "%%~f#" "0" 1>NUL
  196. Set /A "TruncatedFileCount+=1"
  197. ) Else (
  198. Set "File=%%~f#"
  199. Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  200. Set /A "ExcludedFileCount+=1"
  201. )
  202. )
  203. )
  204. Goto:EOF
  205.  
  206.  
  207. :TruncateHiddenFiles
  208. FOR /F "Tokens=* Delims=" %%# in ('Dir /B /S /A-D "%WorkingDir%\*"') DO (
  209.  
  210. If %%~z# NEQ 0 (
  211.  
  212. Set "Exclude="
  213.  
  214. If Defined ExcludeExts (
  215. (
  216. Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  217. ) && (
  218. Call Set "Exclude=True"
  219. )
  220. )
  221.  
  222. If Defined ExcludeNames (
  223. (
  224. Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  225. ) && (
  226. Call Set "Exclude=True"
  227. )
  228. )
  229.  
  230. If Defined ExcludeFiles (
  231. (
  232. Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  233. ) && (
  234. Call Set "Exclude=True"
  235. )
  236. )
  237.  
  238. If Not Defined Exclude (
  239. Set "File=%%~f#"
  240. Call Echo [.] Truncating: %%File:%WorkingDir%=.%%
  241. Call :TakeOwn "%%~f#"
  242. Del /Q "%%~f#"
  243. FSUtil.exe File CreateNew "%%~f#" "0" 1>NUL
  244. Set /A "TruncatedFileCount+=1"
  245. ) Else (
  246. Set "File=%%~f#"
  247. Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  248. Set /A "ExcludedFileCount+=1"
  249. )
  250.  
  251. )
  252. )
  253. Goto:EOF
  254.  
  255.  
  256.  
  257. REM ===============
  258. REM Error Controls:
  259. REM ===============
  260.  
  261. :CheckErrors
  262. :: 'IncludeHiddenFiles' Value check.
  263. If /I "%IncludeHiddenFiles%" NEQ "True" If /I "%IncludeHiddenFiles%" NEQ "False" (
  264. Echo [x] Error parsing parameter 'IncludeHiddenFiles',
  265. Echo     value '%IncludeHiddenFiles%' is not a Boolean value.
  266. Pause&Exit
  267. )
  268.  
  269. Goto:EOF

Saludos
7133  Programación / Scripting / Re: [APORTE] [BATCH] Files2List en: 14 Abril 2014, 04:40 am
Gracias por el aporte!, a mi me servirá de mucho en mi trabajo, asi que gracias!!.

Gracias a ti por comentar.

PD: He actualizado el código en el post de arriba (son pequeños cambios insignificantes).

Saludos!
7134  Sistemas Operativos / Windows / Re: ¡¡¡NO ACTUALICES XP O CAERAS EN UNA TRAMPA DIFÍCIL DE SALIR!!! en: 13 Abril 2014, 04:10 am
Solo me he leido las respuestas de la página 2, porque creo que este tema es un cachondeo y un campo de guerra, tanto por parte de los moderadores/colaboradores como sobretodo (mucho más) por parte tuya y creo que ya se te ha dicho todo lo que se te puede decir y no es necesario que nadie siga ni te sigan en una discusión absurda.

¿seguro que hay que hacer caso a Microsoft?

Si tú prefieres seguir usando un sistema operativo del año 2001 que está a la vuelta de la esquina de denominarse "sistema obsoleto" (si, he dicho obsoleto, ES LO QUE ES, que algunos lo quieran explotar duranto 5 años más es otra cosa) pues será tu decisión y la de los demás, sigue usandolo, como ya te comentaron eres libre de hacerlo, realmente nadie te está poniendo una pistola en la cabeza para que cambies de SO, ¿que quieres que te digamos?...

Para mi es lo mismo que comprar un boligrafo y esperar que te dure toda la vida, pues no, cuando pasa el tiempo este hay que renovarlo por un producto nuevo, no se...¿es que esperas que Windows XP dure para siempre?, ya ha pasado una larga década con WinXP, creo que ya es hora de hacerse a la idea y dejarse de críticas absurdas en contra de la compañia que ha estado manteniendo dicho producto hasta dia de hoy, eso en la informatica y en la tecnología en general no se ve, cuando sale algo nuevo y mejor el producto anterior se reemplaza completamente en menos de 1 año (por decir algo), pero tú y miles de personas más tienen la falta de respeto de quejarse por el deber de tener que actualizar WinXP o de quedarse sin actualizaciones... pues las decisiones de Microsoft en mi opinión son lo más normal del mundo y estoy seguro de que habrían "capado" a WinXP mucho antes si no fuese porque una gran mayoria insiste en seguir usando ese SO y eso le da beneficios a Microsoft, pero dicha gente insiste con elaboradas respuestas tipo "consume muy pocos recursos", coño!. ¿no me digas?, claro que consume muy pocos recursos!, es lo que se espera de un SO de hace una decada, como que es un Windows sin el potencial de una version reciente y los requisitos que estos necesitan.

Saludos!
7135  Sistemas Operativos / Windows / Re: Panel de control no responde en widows 7 en: 13 Abril 2014, 03:54 am
¿Podrías explicar un poco más? Gracias.

IDEM.

Explica "No responde".
7136  Sistemas Operativos / Windows / Re: Guía de personalización de imágenes de implementación de Windows (WIM) (Parte 1) en: 12 Abril 2014, 23:58 pm
Me mataste con las imagenes xD, me gusta saber que estoy en tu Hall Of Fame sobretodo cerca de Carl Sagan, pero no me puedo comparar con ninguno de ellos ni me merezco estar ahi xD.

Con que 1 sola persona se tome la molesta de leer lo que yo me he tomado la molestia en escribir, eso para mi ya es más que suficiente.

¡ Mil gracias por tu forma de agradecer !

Saludos!
7137  Sistemas Operativos / Windows / Guía de personalización de imágenes de implementación de Windows (WIM) (Parte 5) en: 12 Abril 2014, 23:20 pm
5.0
· Introducción a las características/paquetes de Windows




Windows instala consigo muchas características, algunas son visibles y configurables para el usuario como Windows Media Player e Internet Explorer, pero otras son completamente ocultas por seguridad, como drivers, codecs, Telnet, Reconocimiento de voz, y muchas otras cosas más internas, estas características se distribuyen dentro de "paquetes" los cuales están catalogados y se pueden instalar y/o desinstalar dentro de una imagen WIM, paquetes y características se tratan por separado.


· ¿Que herramientas necesitaremos?
·DISM, para el montaje de la imagen y la eliminación de paquetes y características.
· WIM Registry Tweak Tool, para tomar privilegios necesarios en el Hive montado.





5.1
· Obtener información sobre los paquetes

Primero deben usar DISM para montar la imagen Install.wim del DVD de Windows en un directorio (recuerden montar el índice de imagen que quieren manipular), en el punto 3.2 del tutorial está explicado el procedimiento de montaje usando DISM.

En este ejemplo montaré el índice 1 de mi imagen WIM del DVD original de Windows 8.1, que hace referencia a la edición "Windows 8.1 (Core)", la sintaxis del comando es esta:
Código:
Dism.exe /Mount-Image /imageFile:".\Install.wim" /Index:"1" /MountDir:"C:\WinMount"



Seguídamente, para obtener los paquetes visibles y que están instalados en dicha edición/imagen usamos DISM de nuevo usando esta sintaxis:
Código:
Dism.exe /Get-Packages /Image:"Directorio de montaje"

El parámetro /Get-Packages indica que se trata de una operación de obtención de información.
En el parámetro /Image debemos indicar el directorio donde previamente hemos montado la imagen WIM.

Ejemplo:
Código:
Dism.exe /Get-Packages /Image:"C:\WinMount" /Format:Table



También podemos usar la utilidad WIM Registry Tweak Tool para desocultar los paquetes ocultos y obtener los paquetes, usaremos esta sintaxis:
Código:
"WIM Registry Tweak Tool.exe" /p "Directorio de montaje" /l

Ejemplo:
Código:
"WIM Registry Tweak Tool.exe" /p "C:\WinMount" /l



Esto nos creará un archivo "Packages.txt" en el directorio de trabajo del WIM Registry Tweak Tool con los nombres de los paquetes existentes:

Packages.txt
Código:
Adobe-Flash-For-Windows-Package~31bf3856ad364e35~amd64~~6.3.9600.16384
Microsoft-Windows-InternetExplorer-Optional-Package~31bf3856ad364e35~amd64~es-ES~11.0.9600.16384
Microsoft-Windows-InternetExplorer-Optional-Package~31bf3856ad364e35~amd64~~11.0.9600.16384
Microsoft-Windows-InternetExplorer-Package-shell~31bf3856ad364e35~amd64~es-ES~6.3.9600.16384
Microsoft-Windows-InternetExplorer-Package-shell~31bf3856ad364e35~amd64~~6.3.9600.16384
Microsoft-Windows-InternetExplorer-Package-ua~31bf3856ad364e35~amd64~es-ES~6.3.9600.16384
Microsoft-Windows-InternetExplorer-Package-ua~31bf3856ad364e35~amd64~~6.3.9600.16384
Microsoft-Windows-InternetExplorer-Package~31bf3856ad364e35~amd64~es-ES~11.0.9600.16384
Microsoft-Windows-InternetExplorer-Package~31bf3856ad364e35~amd64~~11.0.9600.16384
...


Nota: Los nombres de los paquetes también los pueden encontrar en el directorio montado: ...\Windows\Servicing\Packages





5.2
· Obtener información sobre las características

Nota: Lista de características de Windows 8.1: http://technet.microsoft.com/en-us/library/dn328991.aspx

Para obtener las carcterísticas que están habilitadas en la imagen de Windows usaremos DISM.

Sintaxis
Código:
Dism.exe /Get-Features /Image:"Directorio de montaje" /Format:Table

Ejemplo:
Código:
Dism.exe /Get-Features /Image:"C:\WinMount" /Format:Table







5.3
· Eliminar paquetes

Aqui deben tener MUCHO cuidado, ya que muchos paquetes son esenciales para el correcto funcionamiento de windows (Ej: Drivers, NET Framework, etc...), pero una gran mayoria son inutiles y muchos de nosotros no los querremos tener instalados, pudiendo así ahorrar espacio de instalación y consumo de RAM.

Nota: Los archivos asociados a los paquetes no se eliminan del directorio WinSXS, simplemente dejarán una señal de desinstalación pendiente para cuando vayamos a instalar Windows.

La complejidad para eliminar un paquete puede variar, si tienen más de un índice en una imagen Install.wim es muy probable que los paquetes dependan de otras ediciones (índices) y no se pueden eliminar, además DISM puede dar un error de acceso denegado al montar los Hives del registro, así que para asegurarnos de que todo sale bien, primero utilizaremos la utilidad WIM Registry Tweak Tool para montar el registro y tomar los privilegios necesarios de Admin:

Ejecutaremos WIM Registry Tweak Tool usando esta sintaxis:
Código:
"WIM Registry Tweak Tool.exe" /p "Directorio de montaje"

Ejemplo:
Código:
"WIM Registry Tweak Tool.exe" /p "C:\WinMount"



Ahora ya estamos listos para desinstalar los pquetes que queramos usando DISM (También pueden hacerlo con WIM Registry Tweak Tool, pero es más seguro DISM).

Ejecutaremos DISM con esta sintaxis:
Código:
Dism.exe /Remove-Package /PackageName:"Nombre de la característica" /Imaage:"Directorio de montaje"

Ejemplo:
Código:
Dism.exe /Remove-Package /PackageName:"microsoft-windows-internetexplorer-optional-package~31bf3856ad364e35~amd64~~119600.16384" /Image:"C:\WinMount"



Listo!





5.4
· Desactivar características

El procedimiento para desactivar características es casi identico al de eliminar paquetes pero sin las mayores dificultades que tiene este otro, y con la diferencia además de que no corren ningún riesgo grave en el funcionamiento del SO por desactivar una característica (siempre la pueden volver a habilitar).

Para desactivar una característica de Windows, ejecutamos DISM usando la siguiente sintaxis:
Código:
Dism.exe /Image:"Directorio de montaje" /Disable-Feature /FeatureName:"Nombre de característica"

Ejemplo:
Código:
Dism.exe /Image:"C:\WinMount" /Disable-Feature /FeatureName:"WindowsMediaPlayer"






5.5
· Finalizando la eliminación de paquetes y desactivación de características

El último paso que debemos tener en cuenta es desmontar la imagen y aplicar los cambios realizados,
esto lo haremos utilizando DISM con la siguiente sintaxis:
Código:
Dism.exe /Unmount-Wim /Commit /MountDir:"Directorio de montaje"

Ejemplo:
Código:
Dism.exe /Unmount-Wim /Commit /MountDir:"C:\WinMount"



Nota: Opcionalmente podemos usar la utilidad ImageX para reconstruir la imagen WIM, el manejo de esta operación está explicada en el punto 3.4 del tutorial.





5.6
· Automatizar la eliminación de paquetes

He desarrollado un modo mediante el cual solo necesitan escribir los nombres de los paquetes que quieren eliminar en un archivo de texto y usar un Script Batch, el cual se encargará de Montar, tomar privilegios, eliminar, desmontar y reconstruir, todo de forma automatizada.

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


Una imagen de muestra:



Instrucciones:
Deben crear un archivo llamado "Packages.txt" y añadir los nombres de los paquetes que desenan eliminar (1 nombre por linea).

Ejemplo:
Packages.txt
Código:
microsoft-windows-miracast-driver-package~31bf3856ad364e35~amd64~~6.3.9600.16384
microsoft-windows-mobilepc-client-basic-package~31bf3856ad364e35~amd64~es-es~6.3.9600.16384
microsoft-windows-vpnplugins-package~31bf3856ad364e35~amd64~~6.3.9600.16384
microsoft-windows-webcamexperience-package~31bf3856ad364e35~amd64~~6.3.9600.16384

Seguídamente utilizan este Script.

Nota: Deben configurar los valores de las variables que están documentadas en la cabecera del código.

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] Package List...: %PackageList%
  140. Echo [i] Log File.......: %Logfile%
  141. Echo ===========================
  142. )>"%Logfile%"
  143.  
  144. :: Display starting log info.
  145. Type "%Logfile%"
  146.  
  147. :: Continue writting log.
  148. (
  149. Echo Package conflicts:
  150. Echo ==================
  151. )>>"%LogFile%"
  152. Goto:EOF
  153.  
  154.  
  155. :EndLog
  156. (
  157. Echo [i] Done!
  158. Echo [i] WIM Image Size Before........: %WIMSizeBefore%
  159. Echo [i] WIM Image Size After.........: %WIMSizeAfter%
  160. Echo [i] Packages Successfully Removed: %PackagesRemovedCount% Packages.
  161. Echo [i] Packages Failed To Remove....: %PackagesFailedCount% Packages.
  162. Echo [i] Packages Not Found...........: %PackagesNotFoundCount% Packages.
  163. Echo [i] Elapsed Time.................: %ElapsedTime%
  164. )>>"%LogFile%"
  165.  
  166. :: Display ending information.
  167. CLS
  168. Type "%LogFile%"
  169. Goto:EOF
  170.  
  171.  
  172. :CreateMountDir
  173. :: Create the mount directory.
  174. (
  175. If Not Exist "%MountDir%" If /I "%MountImage%" EQU "True" (
  176. MkDir "%MountDir%" 2>NUL
  177. )
  178. ) || (
  179. Echo [x] Error trying to create the directory "%MountDir%" to mount the Windows Image.
  180. Echo [i] Ensure that you have Admin rights to create the directory.
  181. Echo [i] Ensure that the directory name does not contains illegal characters.
  182. Pause&Exit
  183. )
  184. Goto:EOF
  185.  
  186.  
  187. :Mount
  188. :: Mount the Windows Image into the directory.
  189. Echo [+] Mounting WIM Image...
  190. If /I "%MountImage%" EQU "True" (
  191.  
  192. "%Dism%" /Mount-Image /ImageFile:"%WindowsImage%" /Index:"%ImageIndex%" /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" || (
  193. Echo [x] Error mounting the Image Index "%ImageIndex%" in "%MountDir%"
  194. Echo [i] Ensure that the Image Index exist.
  195. Echo [i] Ensure that you have Admin rights to write inside the directory.
  196. Echo [i] Ensure that the directory is not already mounted.
  197. Echo [i] Ensure that the directory is fully empty.
  198. REM Try to unmount the failed image and discard changes.
  199. If /I "%UnmountImage%" EQU "True" (
  200. Echo [+] Unmounting and discarding changes...
  201. "%Dism%" /Unmount-WIM /Discard /MountDir:"%MountDir%"
  202. )
  203. Pause&Exit
  204. )
  205.  
  206. )
  207. Goto:EOF
  208.  
  209.  
  210. :CleanUp
  211. Echo [+] CleaningUp WIM Image...
  212. "%Dism%" /CleanUp-Image /StartComponentCleanUp /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet
  213. Goto:EOF
  214.  
  215.  
  216. :Unmount
  217. :: Unmount the Windows Image commiting changes.
  218. Echo [+] Unmounting WIM Image...
  219. If /I "%UnmountImage%" EQU "True" (
  220. "%Dism%" /Unmount-WIM /Commit /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%"
  221. )
  222. Goto:EOF
  223.  
  224.  
  225. :Rebuild
  226. If /I "%Rebuild%" EQU "False" (Goto:EOF)
  227.  
  228. Echo [+] Rebuilding WIM image...
  229.  
  230. ("%ImageX%" /Compress Maximum /Export "%WindowsImage%" "*" "%TEMP%\Rebuilt Image.wim" /Check) && (
  231. Del /Q /F "%WindowsImage%" 1>NUL
  232. Move /Y "%TEMP%\Rebuilt Image.wim" "%WindowsImage%" 1>NUL
  233. ) || (
  234. Echo [x] Error rebuilding Image "%WindowsImage%" to "%TEMP%\Rebuilt Image.wim".
  235. )
  236.  
  237. Goto :EOF
  238.  
  239.  
  240. :StartTimer
  241. Set "StartingDate=%Date%"
  242. Set "StarttingTime=%Time:~0,-3%"
  243. Goto :EOF
  244.  
  245.  
  246. :StopTimer
  247. (
  248. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  249. Echo WScript.Echo Minutes ^& " Minutes"
  250. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  251.  
  252. For /F "Tokens=*" %%# In (
  253. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  254. ) Do (
  255. Set "ElapsedTime=%%#"
  256. )
  257.  
  258. Goto:EOF
  259.  
  260.  
  261. :WriteConvertBytesScript
  262. If Exist "%TEMP%\%~n0 Convert Bytes.vbs" (Goto:EOF)
  263. (
  264. Echo Suffix = Array^("Bytes", "KB", "MB", "GB", "TB"^)
  265. Echo Function Convert^(Bytes^)
  266. Echo Convert = convert0^(Bytes, 0^)
  267. Echo End Function
  268. Echo Function Convert0^(Bytes, Level^)
  269. Echo If Bytes ^>= 1024 Then
  270. Echo Bytes = Round^(Bytes / 1024, 2^)
  271. Echo Level = Level + 1
  272. Echo Convert0 = Convert0^(Bytes, Level^)
  273. Echo End If
  274. Echo Convert0 = Bytes ^& " " ^& Suffix^(Level^)
  275. Echo End Function
  276. Echo WScript.Echo Convert^(WScript.Arguments^(0^)^)
  277. )>"%TEMP%\%~n0 Convert Bytes.vbs"
  278. Goto:EOF
  279.  
  280.  
  281. :GetWIMSizeBefore
  282. Call :WriteConvertBytesScript
  283. For %%# in ("%WindowsImage%") Do (Set "WIMSizeBefore=%%~z#")
  284. For /F "Tokens=*" %%# In (
  285. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeBefore%"'
  286. ) Do (
  287. Set "WIMSizeBefore=%%#"
  288. )
  289. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  290. Goto:EOF
  291.  
  292.  
  293. :GetWIMSizeAfter
  294. Call :WriteConvertBytesScript
  295. For %%# in ("%WindowsImage%") Do (Set "WIMSizeAfter=%%~z#")
  296. For /F "Tokens=*" %%# In (
  297. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeAfter%"'
  298. ) Do (
  299. Set "WIMSizeAfter=%%#"
  300. )
  301. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  302. Goto:EOF
  303.  
  304.  
  305. :ParsePackages
  306.  
  307. Set /A "PackagesRemovedCount=0"
  308. Set /A "PackagesFailedCount=0"
  309. Set /A "PackagesNotFoundCount=0"
  310.  
  311. :: Unhide packages and take registry ownership.
  312. "%WIMRegistryTweakTool%" /p "%MountDir%"
  313.  
  314. :: Remove Packages.
  315. For /F "UseBackQ Tokens=* Delims=" %%# In ("%PackageList%") Do (
  316.  
  317. Echo [+] Removing package: %%~#
  318.  
  319. "%Dism%" /Remove-Package /PackageName:"%%~#" /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet 1>NUL
  320.    Call Set /A "ExitCode=%%Errorlevel%%"
  321.  
  322.    (Call Echo "%%ExitCode%%"| Findstr.exe "^\"0\"$" 1>NUL 2>&1) && (
  323.     Call Set /A "PackagesRemovedCount+=1"
  324.    )
  325.  
  326. (Call Echo "%%ExitCode%%"| Findstr.exe "^\"5\"$" 1>NUL 2>&1) && (
  327. Call Set /A "PackagesFailedCount+=1"
  328. Echo Failed to remove package: %%~#>>"%LogFile%"
  329. )
  330.  
  331. (Call Echo "%%ExitCode%%"| Find.exe "-2146498555" 1>NUL 2>&1) && (
  332. Call Set /A "PackagesNotFoundCount+=1"
  333. Echo Package is not installed: %%~#>>"%LogFile%"
  334. )
  335.  
  336. )
  337. Goto:EOF
  338.  
  339.  
  340.  
  341. REM ====================
  342. REM File Error Controls:
  343. REM ====================
  344.  
  345. :CheckErrors
  346. :: WIM File Error-Check.
  347. If /I "MountImage" EQU "True" If Not Exist "%WindowsImage%" (
  348. Echo [x] Windows Image not found at: "%WindowsImage%" | MORE
  349. Pause&Exit
  350. )
  351.  
  352. :: PackageList File Error-Check.
  353. If Not Exist "%PackageList%" (
  354. Echo [x] PackageList not found at: "%PackageList%" | MORE
  355. Pause&Exit
  356. )
  357.  
  358. :: 'DISM.exe' File Error-Check.
  359. If Not Exist "%DISM%" (
  360. Echo [x] 'DISM' process not found at: "%DISM%" | MORE
  361. Pause&Exit
  362. )
  363.  
  364. :: 'ImageX.exe' File Error-Check.
  365. If Not Exist "%ImageX%" (
  366. Echo [x] 'ImageX' process not found at: "%ImageX%" | MORE
  367. Pause&Exit
  368. )
  369.  
  370. :: 'WIM Registry Tweak Tool.exe' File Error-Check.
  371. If Not Exist "%WIMRegistryTweakTool%" (
  372. Echo [x] 'WIM Registry Tweak Tool' process not found at: "%WIMRegistryTweakTool%" | MORE
  373. Pause&Exit
  374. )
  375.  
  376.  
  377. Goto:EOF


Que lo disfruten! ...e intenten no joder Windows eliminando paquetes esenciales para el SO!





5.7
· Automatizar la desactivación de características

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


Una imagen de muestra:



Instrucciones:
Deben crear un archivo de texto con el nombre "Features.txt" y añadir los nombres de las características que que quieren deshabilitar, 1 nombre por cada linea.

Ejemplo:
Features.txt
Código:
DirectPlay
FaxServicesClientPackage
Internet-Explorer-Optional-amd64
Microsoft-Windows-MobilePC-LocationProvider-INF
MicrosoftWindowsPowerShellV2
MicrosoftWindowsPowerShellV2Root
Printing-Foundation-InternetPrinting-Client
Printing-XPSServices-Features
WindowsMediaPlayer
Xps-Foundation-Xps-Viewer


Seguídamente deben usar este Script que he desarrollado el cual se encarga de hacer todas las tareas necesarias.

Nota: Deben configurar los valores de las variables que están documentadas en la cabecera del código.

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] Dism Path......: %Dism%
  133. Echo [i] Dism Log File..: %DismLogfile%
  134. Echo [i] Dism Log Level.: %DismLogLevel%
  135. Echo [i] Feature List...: %FeatureList%
  136. Echo [i] Log File.......: %Logfile%
  137. Echo ===========================
  138. )>"%Logfile%"
  139.  
  140. :: Display starting log info.
  141. Type "%Logfile%"
  142.  
  143. :: Continue writting log.
  144. (
  145. Echo Feature conflicts:
  146. Echo ==================
  147. )>>"%LogFile%"
  148. Goto:EOF
  149.  
  150.  
  151. :EndLog
  152. (
  153. Echo [i] Done!
  154. Echo [i] WIM Image Size Before.........: %WIMSizeBefore%
  155. Echo [i] WIM Image Size After..........: %WIMSizeAfter%
  156. Echo [i] Features Successfully Disabled: %FeaturesRemovedCount% Packages.
  157. Echo [i] Features Failed To Disable....: %FeaturesFailedCount% Packages.
  158. Echo [i] Features Not Found............: %FeaturesNotFoundCount% Packages.
  159. Echo [i] Elapsed Time..................: %ElapsedTime%
  160. )>>"%LogFile%"
  161.  
  162. :: Display ending information.
  163. CLS
  164. Type "%LogFile%"
  165. Goto:EOF
  166.  
  167.  
  168. :CreateMountDir
  169. :: Create the mount directory.
  170. (
  171. If Not Exist "%MountDir%" If /I "%MountImage%" EQU "True" (
  172. MkDir "%MountDir%" 2>NUL
  173. )
  174. ) || (
  175. Echo [x] Error trying to create the directory "%MountDir%" to mount the Windows Image.
  176. Echo [i] Ensure that you have Admin rights to create the directory.
  177. Echo [i] Ensure that the directory name does not contains illegal characters.
  178. Pause&Exit
  179. )
  180. Goto:EOF
  181.  
  182.  
  183. :Mount
  184. :: Mount the Windows Image into the directory.
  185. Echo [+] Mounting WIM Image...
  186. If /I "%MountImage%" EQU "True" (
  187.  
  188. "%Dism%" /Mount-Image /ImageFile:"%WindowsImage%" /Index:"%ImageIndex%" /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" || (
  189. Echo [x] Error mounting the Image Index "%ImageIndex%" in "%MountDir%"
  190. Echo [i] Ensure that the Image Index exist.
  191. Echo [i] Ensure that you have Admin rights to write inside the directory.
  192. Echo [i] Ensure that the directory is not already mounted.
  193. Echo [i] Ensure that the directory is fully empty.
  194. REM Try to unmount the failed image and discard changes.
  195. If /I "%UnmountImage%" EQU "True" (
  196. Echo [+] Unmounting and discarding changes...
  197. "%Dism%" /Unmount-WIM /Discard /MountDir:"%MountDir%"
  198. )
  199. Pause&Exit
  200. )
  201.  
  202. )
  203. Goto:EOF
  204.  
  205.  
  206. :CleanUp
  207. Echo [+] CleaningUp WIM Image...
  208. "%Dism%" /CleanUp-Image /StartComponentCleanUp /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet
  209. Goto:EOF
  210.  
  211.  
  212. :Unmount
  213. :: Unmount the Windows Image commiting changes.
  214. Echo [+] Unmounting WIM Image...
  215. If /I "%UnmountImage%" EQU "True" (
  216. "%Dism%" /Unmount-WIM /Commit /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%"
  217. )
  218. Goto:EOF
  219.  
  220.  
  221. :Rebuild
  222. If /I "%Rebuild%" EQU "False" (Goto:EOF)
  223.  
  224. Echo [+] Rebuilding WIM image...
  225.  
  226. ("%ImageX%" /Compress Maximum /Export "%WindowsImage%" "*" "%TEMP%\Rebuilt Image.wim" /Check) && (
  227. Del /Q /F "%WindowsImage%" 1>NUL
  228. Move /Y "%TEMP%\Rebuilt Image.wim" "%WindowsImage%" 1>NUL
  229. ) || (
  230. Echo [x] Error rebuilding Image "%WindowsImage%" to "%TEMP%\Rebuilt Image.wim".
  231. )
  232.  
  233. Goto :EOF
  234.  
  235.  
  236. :StartTimer
  237. Set "StartingDate=%Date%"
  238. Set "StarttingTime=%Time:~0,-3%"
  239. Goto :EOF
  240.  
  241.  
  242. :StopTimer
  243. (
  244. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  245. Echo WScript.Echo Minutes ^& " Minutes"
  246. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  247.  
  248. For /F "Tokens=*" %%# In (
  249. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  250. ) Do (
  251. Set "ElapsedTime=%%#"
  252. )
  253.  
  254. Goto:EOF
  255.  
  256.  
  257. :WriteConvertBytesScript
  258. If Exist "%TEMP%\%~n0 Convert Bytes.vbs" (Goto:EOF)
  259. (
  260. Echo Suffix = Array^("Bytes", "KB", "MB", "GB", "TB"^)
  261. Echo Function Convert^(Bytes^)
  262. Echo Convert = convert0^(Bytes, 0^)
  263. Echo End Function
  264. Echo Function Convert0^(Bytes, Level^)
  265. Echo If Bytes ^>= 1024 Then
  266. Echo Bytes = Round^(Bytes / 1024, 2^)
  267. Echo Level = Level + 1
  268. Echo Convert0 = Convert0^(Bytes, Level^)
  269. Echo End If
  270. Echo Convert0 = Bytes ^& " " ^& Suffix^(Level^)
  271. Echo End Function
  272. Echo WScript.Echo Convert^(WScript.Arguments^(0^)^)
  273. )>"%TEMP%\%~n0 Convert Bytes.vbs"
  274. Goto:EOF
  275.  
  276.  
  277. :GetWIMSizeBefore
  278. Call :WriteConvertBytesScript
  279. For %%# in ("%WindowsImage%") Do (Set "WIMSizeBefore=%%~z#")
  280. For /F "Tokens=*" %%# In (
  281. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeBefore%"'
  282. ) Do (
  283. Set "WIMSizeBefore=%%#"
  284. )
  285. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  286. Goto:EOF
  287.  
  288.  
  289. :GetWIMSizeAfter
  290. Call :WriteConvertBytesScript
  291. For %%# in ("%WindowsImage%") Do (Set "WIMSizeAfter=%%~z#")
  292. For /F "Tokens=*" %%# In (
  293. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeAfter%"'
  294. ) Do (
  295. Set "WIMSizeAfter=%%#"
  296. )
  297. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  298. Goto:EOF
  299.  
  300.  
  301. :ParseFeatures
  302.  
  303. Set /A "FeaturesRemovedCount=0"
  304. Set /A "FeaturesFailedCount=0"
  305. Set /A "FeaturesNotFoundCount=0"
  306.  
  307. :: Disable Features.
  308. For /F "UseBackQ Tokens=* Delims=" %%# In ("%FeatureList%") Do (
  309.  
  310. Echo [+] Disabling Feature: %%~#
  311.  
  312. "%Dism%" /Disable-Feature /FeatureName:"%%~#" /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet 1>NUL
  313.    Call Set /A "ExitCode=%%Errorlevel%%"
  314.  
  315.    (Call Echo "%%ExitCode%%"| Findstr.exe "^\"0\"$" 1>NUL 2>&1) && (
  316.     Call Set /A "FeaturesRemovedCount+=1"
  317.    )
  318.  
  319. (Call Echo "%%ExitCode%%"| Findstr.exe "^\"5\"$" 1>NUL 2>&1) && (
  320. Call Set /A "FeaturesFailedCount+=1"
  321. Echo Failed to disable feature: %%~#>>"%LogFile%"
  322. )
  323.  
  324. (Call Echo "%%ExitCode%%"| Find.exe "-2146498548" 1>NUL 2>&1) && (
  325. Call Set /A "FeaturesNotFoundCount+=1"
  326. Echo Feature is not found.....: %%~#>>"%LogFile%"
  327. )
  328.  
  329. )
  330. Goto:EOF
  331.  
  332.  
  333.  
  334. REM ====================
  335. REM File Error Controls:
  336. REM ====================
  337.  
  338. :CheckErrors
  339.  
  340. :: WIM File Error-Check.
  341. If /I "MountImage" EQU "True" If Not Exist "%WindowsImage%" (
  342. Echo [x] Windows Image not found at: "%WindowsImage%" | MORE
  343. Pause&Exit
  344. )
  345.  
  346. :: FeatureList File Error-Check.
  347. If Not Exist "%FeatureList%" (
  348. Echo [x] FeatureList not found at: "%FeatureList%" | MORE
  349. Pause&Exit
  350. )
  351.  
  352. :: 'DISM.exe' File Error-Check.
  353. If Not Exist "%DISM%" (
  354. Echo [x] 'DISM' process not found at: "%DISM%" | MORE
  355. Pause&Exit
  356. )
  357.  
  358. :: 'ImageX.exe' File Error-Check.
  359. If Not Exist "%ImageX%" (
  360. Echo [x] 'ImageX' process not found at: "%ImageX%" | MORE
  361. Pause&Exit
  362. )
  363.  
  364. Goto:EOF
7138  Programación / Scripting / Re: [APORTE] [BATCH] Folders2List en: 12 Abril 2014, 15:04 pm
Pero, ¿A que viene la función del tiempo? xD

Es un simple capricho, la verdad es que el script trabaja rápido pero aun así me gusta saber cuanto tarda, estoy acostumbrado a medir el tiempo de ejecución en la programación .NET para optimizar los procedimientos que den señales de conflictos en el tiempo de ejecución.

PD: Gracias por comentar.

Saludos!
7139  Programación / Scripting / [APORTE] [BATCH] Folders2List en: 12 Abril 2014, 00:31 am
Hola

Este Script es el hermano de este otro Script, genera un archivo de texto que contiene la lista de estructura de carpetas del directorio de trabajo y de sus subdirectorios, el directorio de trabajo se puede modificar en las variables del Script, y la lista de capetas se registra usando la ruta relativa de los archivos de dicho directorio de trabajo.

El Script tiene 2 métodos de listar las carpetas, que son: 1. Listado normal, y 2. Listado incluyendo carpetas ocultas.
El Script tiene la funcionalidad de medir el tiempo transcurrido de la operación.

Todo lo que he mencionado se puede configurar en las variables que están documentadas con comentarios de ayuda en el código.

· Una imagen de muestra:


· El código:

Folders2List.cmd
Código
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title Folders2List - 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 writes a textfile containing the relative paths of the folder structure at the working directory and it's subdirectories
  21. Echo  ------------------------------------------------------------------------------------------------------------------------------------
  22.  
  23.  
  24.  
  25. REM ====================
  26. REM User defined values:
  27. REM ====================
  28.  
  29. REM This value indicates the directory where to list it's folder structure.
  30. Set "WorkingDir=%CD%"
  31.  
  32. REM This value indicates the resulting folder list.
  33. Set "OutputFile=%CD%\Folders.txt"
  34.  
  35. REM This value indicates how the hidden folders are threated when listing the folder structure.
  36. REM  True = List folders and also folders with the 'hidden' attribute.
  37. REM False = List only normal folders without the 'hidden' attribute.
  38. Set "IncludeHiddenFolders=True"
  39.  
  40.  
  41.  
  42. REM =====
  43. REM Main:
  44. REM =====
  45.  
  46. :: Display starting info.
  47. Echo [i] Working Directory...: %WorkingDir%
  48. Echo [i] Output file.........: %OutputFile%
  49. Echo [i] Include Hidden Files: %IncludeHiddenFolders%
  50.  
  51. :: Call Methods.
  52. Call :CheckErrors
  53. Call :StartTimer
  54. Call :ListFolders "%IncludeHiddenFolders%"
  55. Call :StopTimer
  56.  
  57. :: Finish.
  58. Echo [i] Done!           | MORE
  59. Echo [i] Listed Folders: %FolderCount% folders.
  60. Echo [i] Elapsed Time..: %ElapsedTime%
  61. Pause&Exit
  62.  
  63.  
  64.  
  65. REM ========
  66. REM Methods:
  67. REM ========
  68.  
  69. :StartTimer
  70. Set "StartingDate=%Date%"
  71. Set "StarttingTime=%Time:~0,-3%"
  72. Goto :EOF
  73.  
  74.  
  75. :StopTimer
  76. (
  77. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  78. Echo WScript.Echo Minutes ^& " Minutes"
  79. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  80.  
  81. For /F "Tokens=*" %%# In (
  82. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  83. ) Do (
  84. Set "ElapsedTime=%%#"
  85. )
  86.  
  87. Goto:EOF
  88.  
  89.  
  90. :ListFolders
  91. Echo [+] Collecting folders, this operation could take some minutes long, please wait...
  92. If /I "%~1" EQU "True"  (Call :ListHiddenFolders)
  93. If /I "%~1" EQU "False" (Call :ListNormalFolders)
  94. Goto:EOF
  95.  
  96.  
  97. :ListNormalFolders
  98. (FOR /D /R "%WorkingDir%" %%# in ("*") DO (
  99. Set "Folder=%%~f#"
  100. Call Echo %%Folder:%WorkingDir%=.%%
  101. Set /A "FolderCount+=1"
  102. ))>"%OutputFile%"
  103. Goto:EOF
  104.  
  105.  
  106. :ListHiddenFolders
  107. (FOR /F "Tokens=* Delims=" %%# in ('Dir /B /S /AD "%WorkingDir%\*"') DO (
  108. Set "Folder=%%~f#"
  109. Call Echo %%Folder:%WorkingDir%=.%%
  110. Set /A "FolderCount+=1"
  111. ))>"%OutputFile%"
  112. Goto:EOF
  113.  
  114.  
  115.  
  116. REM ===============
  117. REM Error Controls:
  118. REM ===============
  119.  
  120. :CheckErrors
  121. :: 'IncludeHiddenFolders' Value check.
  122. If /I "%IncludeHiddenFolders%" NEQ "True" If /I "%IncludeHiddenFolders%" NEQ "False" (
  123. Echo [x] Error parsing parameter 'IncludeHiddenFolders',
  124. Echo     value '%IncludeHiddenFolders%' is not a Boolean value.
  125. Pause&Exit
  126. )
  127.  
  128. Goto:EOF
7140  Programación / Scripting / [APORTE] [BATCH] Files2List en: 11 Abril 2014, 23:34 pm
Hola

He escrito este Script el cual genera un archivo de texto que contiene la lista de archivos con la estructura de archivos del directorio de trabajo y de sus subdirectorios, el directorio de trabajo se puede modificar en las variables del Script, y la lista de archivos en el archivo de listado se registra usando rutas relativa de los archivos de dicho directorio de trabajo.

¿Porque en Batch si siempre me estoy quejando de este "lenguaje"?, para recordar viejos tiempos y porque tuve que escribirlo y testearlo diréctamente desde una VM, con otro lenguaje habria sido aún más coñazo estar testeando de la VM al PC host y viceversa.

Bueno, el script tiene 3 métodos de exclusión de archivos, que son: 1. Por extensión, 2. Por nombres, o 3. Por ruta absoluta, esta última está limitada a la capacidad de caracteres que puede tener un String en Batch (Int32).
El Script tiene 2 métodos de listar los archivos, que son: 1. Listado normal, y 2. Listado incluyendo archivos ocultos.
El Script también tiene capacidad de registrar unformación básica en un Log, y la funcionalidad de medir el tiempo transcurrido de la operación.

Todo lo que he mencionado se puede configurar en las variables que están documentadas con comentarios de ayuda en el código.

Nota: Al explotar la limitada capacidad de Batch añadiendo varias funcionalidades adicionales a un código, este se vuelve demasiado lento, ya que Batch por naturaleza es MUY lento para trabajar, así que ya aviso, si no necesitan excluir archivos entonces no asignen ningún valor en las variables de exclusión.

PD: En el log se guardan las rutas relativas de los archivos que hayan sido excluidas:

Files2List.log
Citar
Excluded Files:
===============

.\Filesize Truncator.bat
.\Folders2List.bat
.\Windows\WinSxS\Get Manifests.bat


· Una imagen de muestra:



· El código:

Files2List.cmd
Código
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title Files2List - 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 writes a textfile containing the relative paths of the file structure at the working directory and it's subdirectories
  21. Echo  ----------------------------------------------------------------------------------------------------------------------------------
  22.  
  23.  
  24.  
  25. REM ====================
  26. REM User defined values:
  27. REM ====================
  28.  
  29. REM This value indicates the directory where to list it's file structure.
  30. Set "WorkingDir=%CD%"
  31.  
  32. REM This value indicates the resulting file list.
  33. Set "OutputFile=%CD%\Files.txt"
  34.  
  35. REM This value indicates the ubication of the logfile that will record info.
  36. Set "Logfile=%CD%\%~n0.log"
  37.  
  38. REM This value indicates the File-Extensions to exclude during the process.
  39. REM ( Use an ';' delimiter to separate multiple extensions )
  40. Set "ExcludeExts=.bat;.cmd"
  41.  
  42. REM This value indicates the filenames to exclude during the process.
  43. REM ( Use an ';' delimiter to separate multiple filenames )
  44. Set "ExcludeNames=%~nx0"
  45.  
  46. REM This value indicates the files to exclude during the process.
  47. REM ( Use an ';' delimiter to separate multiple files )
  48. Set "ExcludeFiles=%OutputFile%;%Logfile%"
  49.  
  50. REM This value indicates how the hidden files are threated when listing the file structure.
  51. REM  True = List files and also files with the 'hidden' attribute.
  52. REM False = List only normal files without the 'hidden' attribute.
  53. Set "IncludeHiddenFiles=True"
  54.  
  55.  
  56.  
  57. REM =====
  58. REM Main:
  59. REM =====
  60.  
  61. :: Call Methods.
  62. Call :CheckErrors
  63. Call :CreateLog
  64. Call :StartTimer
  65. Call :ListFiles "%IncludeHiddenFiles%"
  66. Call :StopTimer
  67. Call :EndLog
  68. Pause&Exit
  69.  
  70.  
  71.  
  72. REM ========
  73. REM Methods:
  74. REM ========
  75.  
  76. :CreateLog
  77. :: Create the Script Logfile and record starting info on it.
  78. FSutil.exe File CreateNew "%LogFile%" "0" 1>NUL
  79. (
  80. Echo       Files 2 List
  81. Echo =========================
  82. Echo   %DATE% ^| %TIME:~0,-3%
  83. Echo /\/\/\/\/\/\/\/\/\/\/\/\/
  84. Echo [i] Working Directory...: %WorkingDir%
  85. Echo [i] Include Hidden Files: %IncludeHiddenFiles%
  86. Echo [i] Excluded Extensions.: %ExcludeExts%
  87. Echo [i] Excluded Filenames..: %ExcludeNames%
  88. Echo [i] Excluded Files......: %ExcludeFiles%
  89. Echo [i] Output file.........: %OutputFile%
  90. Echo [i] Log file............: %LogFile%
  91. Echo =========================
  92. )>"%LogFile%"
  93.  
  94. :: Display starting log info.
  95. Type "%LogFile%" | MORE
  96.  
  97. :: Continue writting log.
  98. (
  99. Echo Excluded Files:
  100. Echo ===============
  101. )>>"%LogFile%"
  102.  
  103. Goto:EOF
  104.  
  105.  
  106. :EndLog
  107. (
  108. Echo [i] Done!           | MORE
  109. Echo [i] Listed Files..: %ListedFileCount% files.
  110. Echo [i] Excluded Files: %ExcludedFileCount% files.
  111. Echo [i] Elapsed Time..: %ElapsedTime%
  112. )>>"%LogFile%"
  113.  
  114. :: Display ending information.
  115. CLS
  116. Type "%LogFile%"
  117. Goto:EOF
  118.  
  119.  
  120. :StartTimer
  121. Set "StartingDate=%Date%"
  122. Set "StarttingTime=%Time:~0,-3%"
  123. Goto :EOF
  124.  
  125.  
  126. :StopTimer
  127. (
  128. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  129. Echo WScript.Echo Minutes ^& " Minutes"
  130. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  131.  
  132. For /F "Tokens=*" %%# In (
  133. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  134. ) Do (
  135. Set "ElapsedTime=%%#"
  136. )
  137.  
  138. Goto:EOF
  139.  
  140.  
  141. :ListFiles
  142. Echo [+] Collecting files, this operation could take some minutes long, please wait...
  143. If /I "%~1" EQU "True"  (Call :ListHiddenFiles)
  144. If /I "%~1" EQU "False" (Call :ListNormalFiles)
  145. Goto:EOF
  146.  
  147.  
  148. :ListNormalFiles
  149. (FOR /R "%WorkingDir%" %%# in ("*") DO (
  150.  
  151. Set "Exclude="
  152.  
  153. If Defined ExcludeExts (
  154. (
  155. Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  156. ) && (
  157. Call Set "Exclude=True"
  158. )
  159. )
  160.  
  161. If Defined ExcludeNames (
  162. (
  163. Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  164. ) && (
  165. Call Set "Exclude=True"
  166. )
  167. )
  168.  
  169. If Defined ExcludeFiles (
  170. (
  171. Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  172. ) && (
  173. Call Set "Exclude=True"
  174. )
  175. )
  176.  
  177. If Not Defined Exclude (
  178. Set "File=%%~f#"
  179. Call Echo %%File:%WorkingDir%=.%%
  180. Set /A "ListedFileCount+=1"
  181. ) Else (
  182. Set "File=%%~f#"
  183. Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  184. Set /A "ExcludedFileCount+=1"
  185. )
  186.  
  187. ))>"%OutputFile%"
  188. Goto :EOF
  189.  
  190.  
  191. :ListHiddenFiles
  192. (FOR /F "Tokens=* Delims=" %%# in ('Dir /B /S /A-D "%WorkingDir%\*"') DO (
  193.  
  194. Set "Exclude="
  195.  
  196. If Defined ExcludeExts (
  197. (
  198. Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  199. ) && (
  200. Call Set "Exclude=True"
  201. )
  202. )
  203.  
  204. If Defined ExcludeNames (
  205. (
  206. Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  207. ) && (
  208. Call Set "Exclude=True"
  209. )
  210. )
  211.  
  212. If Defined ExcludeFiles (
  213. (
  214. Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  215. ) && (
  216. Call Set "Exclude=True"
  217. )
  218. )
  219.  
  220. If Not Defined Exclude (
  221. Set "File=%%~f#"
  222. Call Echo %%File:%WorkingDir%=.%%
  223. Set /A "ListedFileCount+=1"
  224. ) Else (
  225. Set "File=%%~f#"
  226. Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  227. Set /A "ExcludedFileCount+=1"
  228. )
  229.  
  230. ))>"%OutputFile%"
  231. Goto:EOF
  232.  
  233.  
  234.  
  235. REM ===============
  236. REM Error Controls:
  237. REM ===============
  238.  
  239. :CheckErrors
  240. :: 'IncludeHiddenFiles' Value check.
  241. If /I "%IncludeHiddenFiles%" NEQ "True" If /I "%IncludeHiddenFiles%" NEQ "False" (
  242. Echo [x] Error parsing parameter 'IncludeHiddenFiles',
  243. Echo     value '%IncludeHiddenFiles%' is not a Boolean value.
  244. Pause&Exit
  245. )
  246.  
  247. Goto:EOF

Espero que a alguien le sirva de utilidad.

Saludos!
Páginas: 1 ... 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 [714] 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines