gpt4 book ai didi

windows - 用于检查系统中已安装程序及其版本的脚本

转载 作者:可可西里 更新时间:2023-11-01 09:38:36 25 4
gpt4 key购买 nike

我遇到了编写脚本的任务,该脚本首先在 Windows 服务器上启动 32 位 Websphere MQ 客户端的静默安装。然后查看是否安装成功。。。。所以我写了下面的脚本:

  @echo off
REM Author : Akshay Sinha
REM Date Created : 07/05/2012
REM Installing Websphere MQ.......
Msiexec /q /i "%CD%\MSI\IBM WebSphere MQ.msi" /l*v .\install.log /m mif_file TRANSFORMS="1033.mst" AGREETOLICENSE="yes"
echo Script to check if the installation failed !!!
echo Waiting for installaion to complete.......
REM Script will wait for 2 mins, This is to ensure that install.log gets fully generated.
ping 123.45.67.89 -n 1 -w 120000 > nul
echo Wait Over
find /C "Installation operation failed" "%CD%"\install.log > tmp.log
for /f "tokens=1,2,3 delims=:" %%a in (tmp.log) DO (
SET /a FOUND_STR=%%c
echo %FOUND_STR%
)
del tmp.log
SET %FOUND_STR%=%FOUND_STR: =%
echo %FOUND_STR%
if %FOUND_STR% EQU 0 (
echo Installation Of MQ completed without any errors!!!!!
EXIT /B 0
)
if %FOUND_STR% GTR 0 (
echo There were errors while installing MQ.. Pls Verify!!!
EXIT /B 1
)

该脚本对于全新安装工作正常。即,如果上述软件尚未安装在系统上。

但是,我需要增强此脚本,以便它应该检查系统中是否存在 Websphere MQ 及其版本的现有安装。--如果版本不是我们需要的版本(当然,我会从命令行提供),它应该启动卸载。

问题是我不想使用搜索文件系统的方法。那么我该如何使用 WMI 类来完成这项任务呢??我查找了 Win32_Product 类,但它只返回了一个已安装的程序(尽管我的系统上安装了 40 个应用程序)。所以我想知道:1)在系统上搜索特定程序的具体方法是什么。(我对VbScripting或批处理编程持开放态度)2) 已安装软件的注册表项的值在所有系统中是否保持相同,并且在不同的版本中是否有所不同??

提前致谢。

最佳答案

感谢 PA 的提示.. 但是我想出了一个使用 VBScript 的解决方案。我从我原来的批处理文件中调用这个脚本。实际上,我写了一个 vb 脚本,它枚举了可用的不同注册表项:

      SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

并搜索“IBM WebSphere MQ”作为“显示名称”。找到后,它将列出其版本号和“产品代码”。请注意,我们可以从命令行使用“产品代码”进行安装...以下是我编写的脚本。我把它贴在这里供大家使用。请放心使用.........

  '------------------------------------------------------------------------------------      
'Script Name : listMQ.vbs
'Author : Akshay Sinha
'Created : 05/10/12
'Description : This Script attempts to check if the correct version of Websphere MQ is already installed on the system.
' : If found the Script will exit with a ERRORLEVEL of 0.
' : If found but not of correct version... Script will exit with a
' ERRORLEVEL of 1..Which in turn will initiate a Uninstalation
' : If not found, Script will exit with a ERRORLEVEL of 2 and initiate a
' a fresh installation.
' : Syntax: at command prompt ->
' : C:>Cscript listMQ.vbs
' : Check the value of %ERRORLEVEL% after execution.
' : C:>echo %ERRORLEVEL%. Should give 0,1 or 2
'------------------------------------------------------------------------------------

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE

strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry1c = "DisplayVersion"
strEntry1d = "UninstallString"

Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
intVersionNum="1.0.0.0"
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1a, strValue1)
if intRet1 <> "" Then
objReg.GetExpandedStringValue HKLM, strKey & strSubkey, strEntry1a, strValue1
intCompare=StrComp("IBM WebSphere MQ",strValue1,vbTextCompare)
IF intCompare = 0 THEN
objReg.GetExpandedStringValue HKLM, strKey & strSubkey, strEntry1c, intVersionNum
strUninstall=strSubkey
WScript.Echo "Congratulations!! Websphere MQ is already installed on this system"
WScript.Echo strEntry1a & " : " & strValue1
WScript.Echo strEntry1c & " : " & intVersionNum
END IF
End If
Next

IF intVersionNum="1.0.0.0" THEN
WScript.Echo "Sorry Websphere MQ was not found on this system"
WScript.Quit 2
END IF

intVersionCompare=StrComp("7.0.1.5",intVersionNum,vbTextCompare)
IF intVersionCompare = 0 THEN
WScript.Echo "Congratulations!! Correct version of Websphere MQ is installed"
WScript.Echo "Uninstall String for this product is : " & strUninstall
WScript.Quit 0
ELSE
WScript.Echo "Wrong Version of MQ installed"
WScript.Echo "Initiating Unistallation....."
WScript.Quit 1
END IF

这是一个非常 self 解释的脚本。如果您遇到任何问题,请告诉我。

关于windows - 用于检查系统中已安装程序及其版本的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10530911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com