Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getuninstall.bat

(view source code of getuninstall.bat as plain text)

  1. @ECHO OFF
  2. :: Windows Vista and later only
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. FOR /F "delims=." %%A IN ('Ver') DO SET Ver=%%A
  5. FOR %%A IN (%Ver%) DO SET Ver=%%A
  6. IF 1%Ver% LSS 16 GOTO Syntax
  7. SET Ver=
  8.  
  9. :: Check command line arguments
  10. IF     "%~1"=="" GOTO Syntax
  11. IF NOT "%~3"=="" GOTO Syntax
  12. ECHO "%~1" | FINDSTR /R /C:"[/?]" >NUL && GOTO Syntax
  13. SET Computer=
  14. IF NOT "%~2"=="" (
  15. 	PING -a -n 1 "%~2" | FIND /I "%~2" >NUL
  16. 	IF ERRORLEVEL 1 (
  17. 		ECHO.
  18. 		ECHO ERROR: Could not find remote computer "%~2"
  19. 		GOTO Syntax
  20. 	)
  21. )
  22.  
  23. SETLOCAL ENABLEDELAYEDEXPANSION
  24. IF "%~2"=="" (
  25. 	SET Computer=
  26. 	SET Node=
  27. ) ELSE (
  28. 	FOR /F "delims=[" %%A IN ('PING -a -n 1 "%~2" ^| FIND "[" ^| FIND /I "%~2"') DO SET Computer=%%A
  29. 	FOR %%A IN (!Computer!) DO SET Computer=%%A
  30. 	SET Computer=\\!Computer!\
  31. 	SET Node=/Node:"!Computer:~2,-1!"
  32. )
  33.  
  34. SET Count=0
  35. FOR /F "tokens=*" %%A IN ('REG Query %Computer%HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /F "%~1" /D /S 2^>NUL ^| FINDSTR /R /C:"HKEY_"') DO (
  36. 	SET Found=0
  37. 	(REG Query "%Computer%%%~A" /F DisplayName /V /E | FINDSTR /R /I /C:" DisplayName .* .*%Filter%" && SET Found=1) >NUL 2>&1
  38. 	(REG Query "%Computer%%%~A" /F Publisher   /V /E | FINDSTR /R /I /C:" Publisher .* .*%Filter%"   && SET Found=1) >NUL 2>&1
  39. 	IF !Found! EQU 1 (
  40. 		SET /A Count += 1
  41. 		FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F DisplayName    /V /E 2^>NUL ^| FIND /I " DisplayName "')     DO ECHO Program Name      = %%C
  42. 		FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F DisplayVersion /V /E 2^>NUL ^| FIND /I " DisplayVersion "')  DO ECHO Program Version   = %%C
  43. 		FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F Publisher      /V /E 2^>NUL ^| FIND /I " Publisher "')       DO ECHO Publisher         = %%C
  44. 		FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F InstallDate    /V /E 2^>NUL ^| FIND /I " InstallDate "')     DO (
  45. 			SET InstallDate=%%C
  46. 			ECHO Install Date      = !InstallDate:~0,4!-!InstallDate:~4,2!-!InstallDate:~6!
  47. 		)
  48. 		FOR /F "tokens=7 delims=\" %%B IN ("%%~A") DO ECHO Unique Identifier = %%B
  49. 		FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F UninstallString /V /E ^| FIND /I " UninstallString "') DO ECHO Uninstall String  = %%C
  50. 		ECHO.
  51. 	)
  52. )
  53.  
  54. WMIC.EXE %Node% Path Win32_Processor Get DataWidth 2>NUL | FIND "64" >NUL
  55. IF ERRORLEVEL 1 (
  56. 	ECHO.
  57. 	ECHO %Count% programs found
  58. ) ELSE (
  59. 	SET Count32bit=0
  60. 	FOR /F "tokens=*" %%A IN ('REG Query %Computer%HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /F "%~1" /D /S 2^>NUL ^| FINDSTR /R /C:"HKEY_"') DO (
  61. 		SET Found=0
  62. 		(REG Query "%Computer%%%~A" /F DisplayName /V /E | FINDSTR /R /I /C:" DisplayName .* .*%Filter%" && SET Found=1) >NUL 2>&1
  63. 		(REG Query "%Computer%%%~A" /F Publisher   /V /E | FINDSTR /R /I /C:" Publisher .* .*%Filter%"   && SET Found=1) >NUL 2>&1
  64. 		IF !Found! EQU 1 (
  65. 			SET /A Count32bit += 1
  66. 			FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F DisplayName    /V /E 2^>NUL ^| FIND /I " DisplayName "')     DO ECHO Program Name      = %%C
  67. 			FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F DisplayVersion /V /E 2^>NUL ^| FIND /I " DisplayVersion "')  DO ECHO Program Version   = %%C
  68. 			FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F Publisher      /V /E 2^>NUL ^| FIND /I " Publisher "')       DO ECHO Publisher         = %%C
  69. 			FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F InstallDate    /V /E 2^>NUL ^| FIND /I " InstallDate "')     DO (
  70. 				SET InstallDate=%%C
  71. 				ECHO Install Date      = !InstallDate:~0,4!-!InstallDate:~4,2!-!InstallDate:~6!
  72. 			)
  73. 			FOR /F "tokens=7 delims=\" %%B IN ("%%~A") DO ECHO Unique Identifier = %%B
  74. 			FOR /F "tokens=2*" %%B IN ('REG Query "%Computer%%%~A" /F UninstallString /V /E ^| FIND /I " UninstallString "') DO ECHO Uninstall String  = %%C
  75. 			ECHO.
  76. 		)
  77. 	)
  78. 	ECHO.
  79. 	ECHO     %Count% 64-bit programs and !Count32bit! 32-bit programs found
  80. )
  81.  
  82. ENDLOCAL
  83. GOTO:EOF
  84.  
  85.  
  86. :Syntax
  87. ECHO.
  88. ECHO GetUninstall.bat,  Version 2.10 for Windows Vista and later
  89. ECHO List or search uninstall command lines
  90. ECHO.
  91. ECHO Usage:    GETUNINSTALL.BAT  "filter"  [ computer ]
  92. ECHO.
  93. ECHO Where:    "filter"    narrows down the search result to programs whose
  94. ECHO                       uninstall data contains the string "filter"
  95. ECHO           "computer"  is an optional remote computer to be searched
  96. ECHO                       (host name or IP adress)
  97. ECHO.
  98. ECHO Example:  GETUNINSTALL.BAT "Adobe Reader"
  99. ECHO.
  100. ECHO Written by Rob van der Woude
  101. ECHO http://www.robvanderwoude.com
  102.  
  103. :: Set return code
  104. IF "%OS%"=="Windows_NT" EXIT /B 1
  105.  

page last uploaded: 2015-12-04, 16:51