2012-10-19 76 views
7

我有一個應用程序,我必須檢查.NET FW 3.5是否已經安裝。如果已安裝,我想打開一個消息框,要求用戶從Microsoft網站下載並停止安裝。.NET Framework作爲安裝Inno-Setup的先決條件

我發現下面的代碼。你能告訴我:

a)我應該從哪裏調用這個函數? b)我應該檢查.NET FW 3.5 或更高版本是否已安裝?例如如果安裝FW 4.0 - 是否需要安裝3.5?

如果你想在安裝的時候開始,但所示的嚮導形式之前,使用InitializeSetup事件處理程序,它執行支票謝謝

function IsDotNET35Detected(): Boolean; 
var 
    ErrorCode: Integer; 
    netFrameWorkInstalled : Boolean; 
    isInstalled: Cardinal; 
begin 
    result := true; 

    // Check for the .Net 3.5 framework 
    isInstalled := 0; 
    netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', isInstalled); 
    if ((netFrameworkInstalled) and (isInstalled <> 1)) then netFrameworkInstalled := false; 

    if netFrameworkInstalled = false then 
    begin 
    if (MsgBox(ExpandConstant('{cm:dotnetmissing}'), mbConfirmation, MB_YESNO) = idYes) then 
    begin 
     ShellExec('open', 
     'http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&DisplayLang=en', 
     '','',SW_SHOWNORMAL,ewNoWait,ErrorCode); 
    end; 
    result := false; 
    end; 

end; 

回答

6

。當您將False返回給該處理程序時,設置將中止,當爲True時,將開始安裝。這裏是你已經發布的一點點優化腳本:

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 

[CustomMessages] 
DotNetMissing=.NET Framework 3.5 is missing. Do you want to download it ? Setup will now exit! 

[Code] 
function IsDotNET35Detected: Boolean; 
var 
    ErrorCode: Integer; 
    InstallValue: Cardinal; 
begin 
    Result := True; 
    if not RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 
    'Install', InstallValue) or (InstallValue <> 1) then 
    begin 
    Result := False; 
    if MsgBox(ExpandConstant('{cm:DotNetMissing}'), mbConfirmation, MB_YESNO) = IDYES then 
     ShellExec('', 'http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&DisplayLang=en', 
     '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode); 
    end; 
end; 

function InitializeSetup: Boolean; 
begin 
    Result := IsDotNET35Detected; 
end; 
+0

我知道我沒有回答你的問題。我會盡快回來更新...但我現在必須走了... – TLama

+0

謝謝。我會試試看。更高(> 3.5)版本呢?這是真的說,如果FW 4.0安裝,它涵蓋了3.5的需求? –

+0

這取決於您的應用程序,如[本文]中所述(http://msdn.microsoft.com/zh-cn/library/ff602939.aspx)。但沒有人明確表示,如果你安裝了例如在沒有安裝.NET Framework 3.5的計算機上使用.NET 4.5,您可以應用['This kind'](http://support.microsoft.com/kb/318785/en-us)檢測。 – TLama

相關問題