2012-10-11 162 views

回答

17

您不應該檢查確切的版本號。這將在未來發生變化(如4.0> 4.5)。請使用deployment guide中的代碼。

除此之外,你應該嘗試處理從.Net 4.5重新啓動。

Function CheckAndInstallDotNet 
    ; Magic numbers from http://msdn.microsoft.com/en-us/library/ee942965.aspx 
    ClearErrors 
    ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release" 

    IfErrors NotDetected 

    ${If} $0 >= 378389 

     DetailPrint "Microsoft .NET Framework 4.5 is installed ($0)" 
    ${Else} 
    NotDetected: 
     DetailPrint "Installing Microsoft .NET Framework 4.5" 
     SetDetailsPrint listonly 
     ExecWait '"$INSTDIR\Tools\dotNetFx45_Full_setup.exe" /passive /norestart' $0 
     ${If} $0 == 3010 
     ${OrIf} $0 == 1641 
      DetailPrint "Microsoft .NET Framework 4.5 installer requested reboot" 
      SetRebootFlag true 
     ${EndIf} 
     SetDetailsPrint lastused 
     DetailPrint "Microsoft .NET Framework 4.5 installer returned $0" 
    ${EndIf} 

FunctionEnd 
+3

很好的答案!我會恥辱地刪除我的黑客答案!在1641代碼中編輯檢查重新啓動(您的原始版本編譯沒有錯誤) – fiat

+1

感謝這正是我所需要的。爲我節省了一堆時間! –

+1

我一直在嘗試使用不同的代碼片段,但您的代碼是迄今爲止我所見過的最優雅和可讀的解決方案。 +1 –