0
首先,Rob van der Woude爲他的精彩腳本提供了一頂帽子。 http://www.robvanderwoude.com/files/getuninstall_w7.txt 他的腳本是特定於Windows 7的,並不專注於企業。但是,他的腳本爲我們提供了一些非常有價值的見解。Windows使用REG查詢進行卸載日誌記錄
利用的其他資源:
代碼是現在的工作 也看到了許多基於VBS和PowerShell與此相關的腳本。雖然這些都很好,但我們在這些文件格式中遇到了一些問題,如下所述。
生成的日誌顯示正確地爲32位:
SOMESERVER,32BIT,"WinZip Command Line Support Add-On 3.2","",
SOMESERVER,32BIT,"WinZip 16.5","16.5.10095",2012-07-24
生成的日誌顯示正確地爲64位:
ANOTHERSERVER,32BIT,"WinZip 16.5","16.5.10095",2012-11-13
ANOTHERSERVER,64BIT,"WinZip Command Line Support Add-On 3.2","",
當前腳本代碼是:
REM TITLE: Installed Software
REM AUTHOR: Kent Dyer (WITH PIECES PULLED FROM VARIOUS RESOURCES - REFERENCED BELOW)
REM DATE: 2014-02-27
REM VERSION: 1.0 (Initial release)
REM
REM TO DO: This script is to read a text file and does not query AD
REM
REM Have read the warnings against the use of Win32_Product and in fact does not exist
REM on newer systems. It just simply errors with the use of WMIC (VBS: http://ss64.com/nt/installed.txt)
REM ISSUE #1: Because security issues in our enterprise data center, we cannot use VBS without code signing
REM ISSUE #2: PowerShell is certainly an option, but like the batch file as below
REM ISSUE #3: have seen on a certain number of systems where the 32 and 64 bit remote registry key detection
REM Yout must run this script on a 64-bit machine. While you can run it on the 32-bit environment, in
REM to see the 64-bit environent, you have to execute this scrip this week.
REM Geek Uninstaller (http://geekuninstaller.com) shows WinZip-64 (VERSION 16.5.10095) being referenced
REM in the registry at the 32-bit location:
REM HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CD95F661-A5C4-44F5-A6AA-ECDD91C240D3}
REM
REM ISSUE STATEMENT AND DISCUSSION
REM Have seen a number of scripts out on various sites using VBS and PowerShell
REM However, they do not address if there is no "DisplayName" like the one below
REM and consequently have a number of errors when run
REM Gained some very valuable insight at: Rob van der Woude's Scripting Pages
REM URL: http://www.robvanderwoude.com/files/getuninstall_w7.txt
REM However the page is specific to windows 7 only
REM We have a number of Windows 2003/2008 servers and have a mix of 32 and 64-bit installations
REM WinZip in the example shown does have both 32-bit and 64-bit installations to illustrate
REM the use of this script
REM DEFINE A LIST OF COMPUTERS
SET COMPLIST=installed_computers.txt
REM CREATE A LOG
SET LOGDATA=results.txt
REM SOFTWARE TO SEARCH FOR. HAVE ONLY USED PARTIAL STRINGS.
REM HAVE NOT USED FULL STRINGS LIKE WinZip 16.5
SET SRCH=WinZip
REM WE NEED TO DELETE THE EXISTING LOG IF IT EXISTS
IF EXIST %LOGDATA% DEL %LOGDATA%
ECHO DisplayName,DisplayVersion,InstallDate >> %LOGDATA%
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1" %%A IN (%COMPLIST%) DO (
SET CNAME=%%A
rem SET CNAME=LTCRSADEVAP06
REM ECHO !CNAME! >> %LOGDATA%
REM SECTION TO LIST 32-BIT SOFTWARE
FOR /F "tokens=*" %%A IN ('REG Query \\!CNAME!\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /F "%~1" /D /S 2^>NUL ^| FINDSTR /R /B /C:"HKEY_"') DO (
REM USE THIS NEXT LINE TO LIST SPECIFC 32-BIT SOFTWARE
REG Query "\\!CNAME!\%%~A" /F DisplayName /E | FINDSTR /R /I /C:" DisplayName .* .*!SRCH!" >NUL 2>&1
REM USE THIS NEXT LINE TO LIST ALL 32-BIT SOFTWARE
REM REG Query "\\!CNAME!\%%~A" /F DisplayName /V /E | FINDSTR /R /I /C:" DisplayName .* .*%~1" >NUL 2>&1
IF NOT ERRORLEVEL 1 (
SET /A Count += 1
FOR /F "tokens=2*" %%B IN ('REG Query "\\!CNAME!\%%~A" /F DisplayName /V /E 2^>NUL ^| FIND /I " DisplayName "') DO (
SET DisplayName=%%C
)
FOR /F "tokens=2*" %%B IN ('REG Query "\\!CNAME!\%%~A" /F DisplayVersion /V /E 2^>NUL ^| FIND /I " DisplayVersion "') DO (
SET DisplayVersion=%%C
)
FOR /F "tokens=2*" %%B IN ('REG Query "\\!CNAME!\%%~A" /F InstallDate /V /E 2^>NUL ^| FIND /I " InstallDate "') DO (
SET InstallDate=%%C
SET InstallDate=!InstallDate:~0,4!-!InstallDate:~4,2!-!InstallDate:~6!
)
ECHO.
ECHO !CNAME!,32BIT,"!DisplayName!","!DisplayVersion!",!InstallDate! >> %LOGDATA%
SET DisplayName=
SET DisplayVersion=
SET InstallDate=
)
)
REM IF YOU DO NOT RUN THIS ON A 64-BIT SYSTEM, IT WILL NEVER DETECT 64-BIT SOFTWARE!!
WMIC.EXE Path Win32_Processor Get DataWidth 2>NUL | FIND "64" >NUL
IF ERRORLEVEL 1 (
ECHO.
ECHO %Count% programs found
) ELSE (
SET Count32bit=0
FOR /F "tokens=*" %%A IN ('REG Query \\!CNAME!\HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /F "%~1" /D /S 2^>NUL ^| FINDSTR /R /B /C:"HKEY_"') DO (
REM USE THIS NEXT LINE TO LIST SPECIFC 64-bit SOFTWARE
REG Query "\\!CNAME!\%%~A" /F DisplayName /E | FINDSTR /R /I /C:" DisplayName .* .*!SRCH!" >NUL 2>&1
REM USE THIS NEXT LINE TO LIST ALL 64-BIT SOFTWARE
REM REG Query "\\!CNAME!\%%~A" /F DisplayName /V /E | FINDSTR /R /I /C:" DisplayName .* .*%~1" >NUL 2>&1
IF NOT ERRORLEVEL 1 (
SET /A Count32bit += 1
FOR /F "tokens=2*" %%B IN ('REG Query "\\!CNAME!\%%~A" /F DisplayName /V /E 2^>NUL ^| FIND /I " DisplayName "') DO (
SET DisplayName=%%C
)
FOR /F "tokens=2*" %%B IN ('REG Query "\\!CNAME!\%%~A" /F DisplayVersion /V /E 2^>NUL ^| FIND /I " DisplayVersion "') DO (
SET DisplayVersion=%%C
)
FOR /F "tokens=2*" %%B IN ('REG Query "\\!CNAME!\%%~A" /F InstallDate /V /E 2^>NUL ^| FIND /I " InstallDate "') DO (
SET InstallDate=%%C
SET InstallDate=!InstallDate:~0,4!-!InstallDate:~4,2!-!InstallDate:~6!
)
ECHO.
ECHO !CNAME!,64BIT,"!DisplayName!","!DisplayVersion!",!InstallDate! >> %LOGDATA%
SET DisplayName=
SET DisplayVersion=
SET InstallDate=
)
)
)
)
ECHO. >> %LOGDATA%
ECHO %Count% 64-bit programs and !Count32bit! 32-bit programs found >> %LOGDATA%
PAUSE