InstallShield判断DotNetFramework指定版本是否安装的脚本代码

// @param szVersion Version to check, e.g. "v2.0", "v3.5" and so on.

function DetectDotNet(szVersion)
    NUMBER nRootKey, nResult;
    LIST lstVersions;
    BOOL bRet;
    STRING szString;
begin
    bRet = FALSE;
    nRootKey = HKEY_LOCAL_MACHINE;
    lstVersions = ListCreate(STRINGLIST);
    if (lstVersions = LIST_NULL) then
        MessageBox ("Unable to create necessary lists.", SEVERE);
        abort;
    endif;
   
    if (RegDBSetDefaultRoot(nRootKey) = 0) then
        nResult = RegDBQueryKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP",
            REGDB_KEYS, lstVersions);
        if (nResult = 0) then
            // Get the first string in the list.
            nResult = ListGetFirstString(lstVersions, szString);
   
            // Loop while list items continue to be retrieved.
            while (nResult != END_OF_LIST)
                // Detect the current element.
                if (StrFind(szString, szVersion) = 0) then
                    bRet = TRUE;
                    nResult = END_OF_LIST;  // Force to exit
                else
                    // Get the next string in the list.
                    nResult = ListGetNextString(lstVersions, szString);
                endif;
            endwhile;
        endif;
    endif;
   
    ListDestroy(lstVersions);  

    return bRet;
end;

无人值守安装.Net Framework 3.5的批处理脚本(传入参数是dotnetfx35.exe所在的绝对目录,解决自动连网下载的问题):

@echo off
setlocal

set INSTALLER31="%~1WindowsInstaller-KB893803-v2-x86.exe"
set DOTNETFX35="%~1dotnetfx35.exe"
set NDP35SP1="%~1NDP35SP1-KB958484-x86.exe"

echo Installing %INSTALLER31%
%INSTALLER31% /quiet /norestart /nobackup

echo Extracting %DOTNETFX35%
%DOTNETFX35% /x:%TEMP% /passive

cd /d "%TEMP%\wcu\dotNetFramework"

echo Installing dotNetFx35setup.exe
dotNetFx35setup.exe /lang:ENU /norestart /passive

echo Removing extracted files
cd /d "%TEMP%"
rd /s /q wcu

echo Installing %NDP35SP1%
%NDP35SP1% /norestart /passive

endlocal

Tags:

Leave a Reply


提醒: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。请务必注意user必须和评论者名相匹配(大小写一致)。