@echo off & setlocal enabledelayedexpansion
title 已安装程序列表获取脚本 By 依梦琴瑶
:: 设置日志文件保存路径,不存在时会自动创建
set LogSaveDir=D:\MyLog
set UnKey=Microsoft\Windows\CurrentVersion\Uninstall
if /i "%PROCESSOR_IDENTIFIER:~,3%"=="x86" goto x86
echo 正在努力获取本机已安装程序列表,请稍后。。。
(echo Name^|^|Version^|^|Publisher^|^|InstallDate
for /f "delims=" %%i in ('reg query "HKLM\SOFTWARE\%UnKey%"') do (
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayName 2^>nul') do (
set "Name=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayVersion 2^>nul') do (
set "Version=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v Publisher 2^>nul') do (
set "Publisher=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v InstallDate 2^>nul') do (
set "InstallDate=%%~k"
)
if not defined Name set Name=未知程序名
if not defined Version set Version=未知版本号
if not defined Publisher set Publisher=未知发布者
if not defined InstallDate set InstallDate=未知安装时间
if not "!Name!||!Version!||!Publisher!||!InstallDate!"=="未知程序名||未知版本号||未知发布者||未知安装时间" echo !Name!^|^|!Version!^|^|!Publisher!^|^|!InstallDate!
set "Name=" & set "Version=" & set "Publisher=" & set "InstallDate="
))>ymqy.$
(for /f "delims=" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\%UnKey%"') do (
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayName 2^>nul') do (
set "Name=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayVersion 2^>nul') do (
set "Version=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v Publisher 2^>nul') do (
set "Publisher=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v InstallDate 2^>nul') do (
set "InstallDate=%%~k"
)
if not defined Name set Name=未知程序名
if not defined Version set Version=未知版本号
if not defined Publisher set Publisher=未知发布者
if not defined InstallDate set InstallDate=未知安装时间
if not "!Name!||!Version!||!Publisher!||!InstallDate!"=="未知程序名||未知版本号||未知发布者||未知安装时间" echo !Name!^|^|!Version!^|^|!Publisher!^|^|!InstallDate!
set "Name=" & set "Version=" & set "Publisher=" & set "InstallDate="
))>>ymqy.$
(for /f "delims=" %%i in ('reg query "HKCU\SOFTWARE\%UnKey%"') do (
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayName 2^>nul') do (
set "Name=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayVersion 2^>nul') do (
set "Version=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v Publisher 2^>nul') do (
set "Publisher=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v InstallDate 2^>nul') do (
set "InstallDate=%%~k"
)
if not defined Name set Name=未知程序名
if not defined Version set Version=未知版本号
if not defined Publisher set Publisher=未知发布者
if not defined InstallDate set InstallDate=未知安装时间
if not "!Name!||!Version!||!Publisher!||!InstallDate!"=="未知程序名||未知版本号||未知发布者||未知安装时间" echo !Name!^|^|!Version!^|^|!Publisher!^|^|!InstallDate!
set "Name=" & set "Version=" & set "Publisher=" & set "InstallDate="
))>>ymqy.$
goto SortingList
:x86
(echo Name^|^|Version^|^|Publisher^|^|InstallDate
for /f "delims=" %%i in ('reg query "HKLM\SOFTWARE\%UnKey%"') do (
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayName 2^>nul') do (
set "Name=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayVersion 2^>nul') do (
set "Version=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v Publisher 2^>nul') do (
set "Publisher=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v InstallDate 2^>nul') do (
set "InstallDate=%%~k"
)
if not defined Name set Name=未知程序名
if not defined Version set Version=未知版本号
if not defined Publisher set Publisher=未知发布者
if not defined InstallDate set InstallDate=未知安装时间
if not "!Name!||!Version!||!Publisher!||!InstallDate!"=="未知程序名||未知版本号||未知发布者||未知安装时间" echo !Name!^|^|!Version!^|^|!Publisher!^|^|!InstallDate!
set "Name=" & set "Version=" & set "Publisher=" & set "InstallDate="
))>ymqy.$
(for /f "delims=" %%i in ('reg query "HKCU\SOFTWARE\%UnKey%"') do (
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayName 2^>nul') do (
set "Name=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v DisplayVersion 2^>nul') do (
set "Version=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v Publisher 2^>nul') do (
set "Publisher=%%~k"
)
for /f "skip=2 tokens=2* delims= " %%j in ('reg query "%%~i" /v InstallDate 2^>nul') do (
set "InstallDate=%%~k"
)
if not defined Name set Name=未知程序名
if not defined Version set Version=未知版本号
if not defined Publisher set Publisher=未知发布者
if not defined InstallDate set InstallDate=未知安装时间
if not "!Name!||!Version!||!Publisher!||!InstallDate!"=="未知程序名||未知版本号||未知发布者||未知安装时间" echo !Name!^|^|!Version!^|^|!Publisher!^|^|!InstallDate!
set "Name=" & set "Version=" & set "Publisher=" & set "InstallDate="
))>>ymqy.$
:SortingList
for /f "skip=1 tokens=1 delims=[]" %%a in ('find /n "::SortingListVBS::" "%~0"') do set Line=%%~a
more +%Line% "%~0">Sorting.VBS
if not exist "%LogSaveDir%" md "%LogSaveDir%"
(cscript //nologo //e:jscript "Sorting.VBS" < ymqy.$)>"%LogSaveDir%\%COMPUTERNAME%.Log"
del /f/q ymqy.$ Sorting.VBS
echo 本机已安装程序列表已输出至 "%LogSaveDir%\%COMPUTERNAME%.Log"
pause
exit
::SortingListVBS::
var i = 0, arr = [], max = [];
var reg = /[^\x00-\xff]/g;
while(!WSH.StdIn.AtEndOfStream){
var strLine = WSH.StdIn.ReadLine();
if(!/^\s*$/.test(strLine)) {
arr[i] = strLine.split('||');
for(var j=0; jvar len = arr[i][j].replace(reg, '..').length;
if(!max[j] || len > max[j]) max[j] = len;
}
i++;
}
}
for(var i=0; ivar s = '';
for(var j=0; jvar len = max[j] - arr[i][j].replace(reg, '..').length;
var space = ' ';
for (var k=0; ks += arr[i][j] + space;
}
WScript.Echo(s);
}
最终的效果是这样的,比WMIC多了两个详细的项目,那就是软件发布者和安装时间。