2012-05-10 59 views
3

我遇到了編寫腳本的任務,該腳本首先在Windows服務器上啓動Websphere MQ客戶端32位的無提示安裝。然後檢查是否安裝成功與否..... 所以我寫了下面的腳本:用於檢查已安裝程序及其版本的系統腳本

@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)搜索某個特定程序的具體方法是什麼(我願意接受Vb腳本編程或批量編程) 2)所有系統中已安裝軟件的註冊表鍵值是否保持不變,並且它與不同的virsion有所不同?

在此先感謝。

+0

+1全部問題描述+陳述良好的問題 –

回答

0

感謝PA爲TIP。但是我想出了使用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 

這是一個非常自我解釋script..Please讓我知道如果你遇到任何問題。

0

你不需要WMI來實現這一點。只需查詢註冊表hklm\software\Microsoft\Windows\CurrentVersion\Uninstall\鍵,然後檢查返回的值。

開始沿着這碼事...

for /f "tokens=*" %%a in ('reg query hklm\software\Microsoft\Windows\CurrentVersion\Uninstall\ ^| find /i "IBM Websphere MQ" ') do (
echo %%a 
) 
相關問題