2012-05-10 3 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) 특정 프로그램을 검색하는 구체적인 방법은 무엇인가? 시스템 (VbScripting 또는 배치 프로그래밍에 개방적입니다.) 2) 설치된 소프트웨어에 대한 레지스트리 키의 값은 모든 시스템에서 동일하게 유지되며 다른 버전에 따라 달라 집니까 ??

미리 감사드립니다.

+0

+1 전체 문제 설명 + 잘 설명 된 질문 –

답변

0

감사 PA ...이 코드를 따라 뭔가로 시작합니다. 원래 배치 파일에서이 스크립트를 호출합니다.

 SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ 

하고 "표시 이름"과 같은 "는 IBM WebSphere MQ"를 검색 : 는 사실은 내가에서 사용할 수있는 다른 레지스트리 키를 열거 비주얼 베이직 스크립트를 썼다. 발견되면 버전 번호와 "제품 코드"가 표시됩니다. 명령 줄에서 설치 목적으로 "제품 코드"를 사용할 수 있습니다 ... 다음은 제가 작성한 스크립트입니다. 나는 모든 사람이 사용할 수 있도록 여기에 게시하고 있습니다. 이 설명 script..Please이 문제가 발생하는 경우 알려 꽤 자체입니다 ..........

'------------------------------------------------------------------------------------  
    '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 

를 사용 주시기 바랍니다.

0

이렇게하려면 WMI가 필요하지 않습니다. 레지스트리에 hklm\software\Microsoft\Windows\CurrentVersion\Uninstall\ 키를 쿼리하고 반환 된 값을 확인하십시오.

그러나 내가 VBScript를를 사용하여 솔루션을 함께했다 .. 그 팁에 대한

for /f "tokens=*" %%a in ('reg query hklm\software\Microsoft\Windows\CurrentVersion\Uninstall\ ^| find /i "IBM Websphere MQ" ') do (
echo %%a 
) 
관련 문제