问题和当前输出:未在安装了Win XP x86的计算机上创建%file3% (%~dp0%computername%-programs_unsorted.txt)。但是,%file3%是在安装了Win 7 x86的系统上创建的。
需要使用以下输出创建%file3% (例如):
Adobe AIR
Adobe AIR
Adobe Flash Player 13 ActiveX
Adobe Reader XI (11.0.07)
Adobe Shockwave Player 12.1
Cisco AnyConnect Network Access Manager
Cisco AnyConnect Secure Mobility Client
Cisco AnyConnect Secure Mobility Client
Cisco Jabber Video for TelePresence
Citrix Authentication Manager 批次编码:
@echo OFF
setlocal enableextensions enabledelayedexpansion
set "Version_tool=v39"
SET "file3=%~dp0%computername%-programs_unsorted.txt"
If Exist %file3% Del %file3%
Rem -------- Win XP x86 commands ---------
:WinXPx86
echo Win XP x86...
for /f "tokens=* delims=" %%A in (
'REG Query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S ^| find "DisplayName"'
) do echo %%A %%B %%C %%D %%E>> %file3%
pause
for /f "tokens=* delims=" %%A in (
'REG Query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S ^| find "QuietDisplayName"'
) do echo %%A %%B %%C %%D %%E>> %file3%
echo %computername%-programs_unsorted.txt created ...
pause
goto Continue发布于 2015-01-22 11:11:59
此批处理代码段在XP或Win7上都不能按说明工作。我为%file3%设置了一个值,这样我就可以在我的系统上运行它。
只要分隔符是空的("delims="),就不会在这两个版本的Windows上为我编写%file3%。如果我在等号后面加一个空格("delims= "),我就会开始得到如下输出。
在两个Windows版本上,我都得到了一个如下所示的文件:
DisplayName REG_SZ Microsoft Help Viewer 1.1 %B %C %D %E
DisplayName REG_SZ Microsoft Team Foundation Server 2010 Object Model - ENU %B %C %D %E
DisplayName REG_SZ Microsoft Visual Studio 2010 Tools for Office Runtime (x64) %B %C %D %E
DisplayName REG_SZ Intel(R) Network Connections Drivers %B %C %D %E
DisplayName REG_SZ Microsoft Sync Framework Services v1.0 SP1 (x64) %B %C %D %E
...%%A持有整行的值,因为"tokens=*“表示整行都是一个标记。在命令行帮助中:
如果tokens=字符串中的最后一个字符是星号,则会分配一个额外的变量,并在解析最后一个标记之后接收该行中的剩余文本。
因此,每一整行都存储在%%A中,而其他变量只是作为它们自己的名称。
要获得您所描述的输出,请更改FOR命令。添加空格作为分隔符,并更改所需的标记。在XP中使用"tokens=2,*“,在Win7中使用"tokens=3,*”。下面是一个有效的XP示例:
for /f "tokens=2,* delims= " %%A in (
'REG Query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /S ^| find "DisplayName"'
) do echo %%A %%B>> %file3%当我进行这些更改时,程序输出在XP和Win7中都如下所示:
Microsoft Help Viewer 1.1
Microsoft Team Foundation Server 2010 Object Model - ENU
Microsoft Visual Studio 2010 Tools for Office Runtime (x64)
Intel(R) Network Connections Drivers
Microsoft Sync Framework Services v1.0 SP1 (x64)在XP上,列出了大量的安全更新。XP上的find筛选器也匹配"ParentDisplayName“。不知道你是不是想改变这种情况。它列出了许多重复项。
https://stackoverflow.com/questions/28069428
复制相似问题