批处理文件版本相处具体安装的软件 [英] Batch file to get specific installed software along with version

查看:117
本文介绍了批处理文件版本相处具体安装的软件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,发现安装特定的软件,但我有麻烦也越来越软件的版本。例如,假设我正在安装的所有Microsoft软件的列表。以下是我迄今:

I have a script which finds specific installed software but I am having trouble also getting the software's version. For example, say I am getting a list of all Microsoft software installed. Here is what I have thus far:

echo software installed > software_list.txt
echo ================= >>software_list.txt
reg export HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall temp1.txt
find "Microsoft" temp1.txt| find "DisplayName" > temp2.txt
for /f "tokens=2,3 delims==" %%a in (temp2.txt) do (echo %%a >> software_list.txt)

start notepad "software_list.txt"

del temp1.txt temp2.txt

我如何也得从章出口DisplayVersion?如果我和DisplayVersion替换显示名称,没有什么是竟然发现。或者,有另一种途径,我应该在这里接受?

How can I also get the DisplayVersion from the reg export? If I replace DisplayName with DisplayVersion, nothing is even found. Or, is there another avenue I should be taking here?

推荐答案

DisplayVersion 在结果空输出,因为这条线的工作方式:

Replacing DisplayName with DisplayVersion results in an empty output because of the way this line works:

find "Microsoft" temp1.txt| find "DisplayName" > temp2.txt

这是什么行代码中发现的 temp2.​​txt 文件同时包含的微软的和的显示名称子(也就是,它找到名称中包含的产品的微软的)。与线条的 DisplayVersion 的,在轮到自己,包含产品版本号,并且不包含这个词的微软的,这就是为什么你会得到空的输出。

What this line does is it finds all lines in the temp2.txt file that contain both the Microsoft and DisplayName substrings (that is, it finds the products whose names contain Microsoft). The lines with DisplayVersion, in their turn, contain product version numbers and don't contain the word Microsoft, which is why you get empty output.

我可以建议一对夫妇使用替代解决方案 WMI

I can suggest a couple of alternative solutions that use WMI:


  1. 解析 HKLM \\ SOFTWARE \\微软\\的Windows \\ CurrentVersion \\卸载使用脚本(VBScript中,PowerShell的等),而不是一个批处理文件子项,因为脚本语言提供文本操作提供更好的支持。下面是输出安装的Microsoft产品的名称和版本一个VBScript示例(产品名称中包含的微软的,更precise):

  1. Parse the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall subkeys using a script (VBScript, PowerShell etc) rather than a batch file, because scripting languages offer much better support for text manipulation. Here's a VBScript example that outputs the names and versions of installed Microsoft products (products whose names contain Microsoft, to be more precise):

On Error Resume Next


Const strComputer = "."
Const HKLM        = &H80000002
Const strKeyPath  = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"


Dim oReg, arrSubKeys, strProduct, strDisplayName, strVersion


Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
     strComputer & "\root\default:StdRegProv")


' Enumerate the subkeys of the Uninstall key
oReg.EnumKey HKLM, strKeyPath, arrSubKeys
For Each strProduct In arrSubKeys
  ' Get the product's display name
  oReg.GetStringValue HKLM, strKeyPath & "\" & strProduct, "DisplayName", strDisplayName
  ' Process only products whose name contain 'Microsoft'
  If InStr(1, strDisplayName, "Microsoft", vbTextCompare) > 0 Then
    ' Get the product's display version
    oReg.GetStringValue HKLM, strKeyPath & "\" & strProduct, "DisplayVersion", strVersion
    WScript.Echo strDisplayName & vbTab & strVersion
  End If
Next

用法:

cscript //nologo productlist.vbs
cscript //nologo productlist.vbs > productlist.txt


  • 如果你感兴趣的是由 Windows安装程序安装的软件,您可以通过查询WMI <获取关于该软件的信息(如姓名,供应商,版本等) code>的Win32_Product 类。在 WMIC 实用程序可以直接在命令行和批处理文件做到这一点。 Here're一些例子:

  • If the software you're interested in is installed by the Windows Installer, you can get info about that software (such as the name, vendor, version etc) by querying the WMI Win32_Product class. The wmic utility lets you do this directly from the command line and batch files. Here're some examples:


    • 打印的姓名和安装的软件版本:

    • Print the names and versions of installed software:

    wmic product get Name, Version
    


  • 列出所有安装的Microsoft产品:

  • List all installed Microsoft products:

    wmic product where "Vendor like '%Microsoft%'" get Name, Version
    


  • 列出已安装的产品,拥有的办公室的在他们的名字:

    wmic product where "Name like '%Office%'" get Name, Version
    


  • WMIC 输出保存到一个文件中,你可以使用 /输出(可选) /格式参数,例如:

    To save the wmic output to a file, you can use the /output and (optionally) /format parameters, e.g.:

    wmic /output:software.txt product get Name, Version
    wmic /output:software.htm product get Name, Version /format:htable
    

    有关 WMIC 语法的详细信息,请参阅 WMIC /?

    For more information about the wmic syntax, see wmic /?

    这篇关于批处理文件版本相处具体安装的软件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆