我想創建一個NSIS安裝程序,檢查.NET Framework並安裝它,如果它不存在。你能爲我指出一個腳本嗎?我對NSIS很陌生。檢查.NET Framework的NSIS安裝程序
回答
!define DOT_MAJOR "2"
!define DOT_MINOR "0"
Function IsDotNetInstalled
StrCpy $0 "0"
StrCpy $1 "SOFTWARE\Microsoft\.NETFramework" ;registry entry to look in.
StrCpy $2 0
StartEnum:
;Enumerate the versions installed.
EnumRegKey $3 HKLM "$1\policy" $2
;If we don't find any versions installed, it's not here.
StrCmp $3 "" noDotNet notEmpty
;We found something.
notEmpty:
;Find out if the RegKey starts with 'v'.
;If it doesn't, goto the next key.
StrCpy $4 $3 1 0
StrCmp $4 "v" +1 goNext
StrCpy $4 $3 1 1
;It starts with 'v'. Now check to see how the installed major version
;relates to our required major version.
;If it's equal check the minor version, if it's greater,
;we found a good RegKey.
IntCmp $4 ${DOT_MAJOR} +1 goNext yesDotNetReg
;Check the minor version. If it's equal or greater to our requested
;version then we're good.
StrCpy $4 $3 1 3
IntCmp $4 ${DOT_MINOR} yesDotNetReg goNext yesDotNetReg
goNext:
;Go to the next RegKey.
IntOp $2 $2 + 1
goto StartEnum
yesDotNetReg:
;Now that we've found a good RegKey, let's make sure it's actually
;installed by getting the install path and checking to see if the
;mscorlib.dll exists.
EnumRegValue $2 HKLM "$1\policy\$3" 0
;$2 should equal whatever comes after the major and minor versions
;(ie, v1.1.4322)
StrCmp $2 "" noDotNet
ReadRegStr $4 HKLM $1 "InstallRoot"
;Hopefully the install root isn't empty.
StrCmp $4 "" noDotNet
;build the actuall directory path to mscorlib.dll.
StrCpy $4 "$4$3.$2\mscorlib.dll"
IfFileExists $4 yesDotNet noDotNet
noDotNet:
;Nope, something went wrong along the way. Looks like the proper .NETFramework isn't installed.
Push "NOK"
Return
yesDotNet:
;Everything checks out. Go on with the rest of the installation.
Push "OK"
Return
FunctionEnd
下面的代碼檢查.net 3.5是否安裝,如果沒有,它會靜默安裝它。它使用宏來檢查註冊表中是否存在指定的密鑰。
宏:
# This macro checks if a certain key exists in the registry
!macro IfKeyExists ROOT MAIN_KEY KEY
push $R0
push $R1
!define Index 'Line${__LINE__}'
StrCpy $R1 "0"
"${Index}-Loop:"
; Check for Key
EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1"
StrCmp $R0 "" "${Index}-False"
IntOp $R1 $R1 + 1
StrCmp $R0 "${KEY}" "${Index}-True" "${Index}-Loop"
"${Index}-True:"
;Return 1 if found
push "1"
goto "${Index}-End"
"${Index}-False:"
;Return 0 if not found
push "0"
goto "${Index}-End"
"${Index}-End:"
!undef Index
exch 2
pop $R0
pop $R1
!macroend
功能:
# The function that checks if .net is already installed
Function CheckDotNet
!insertmacro IfKeyExists HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}"
Pop $R0
${If} $R0 == 0 # not installed NOTE: /q:a means this will be a silent installation
ExecWait "$EXEDIR\dotnetfx35.exe /q:a"
Goto endPrerequisites
${EndIf}
endPrerequisites:
# Code to execute after checking/installing (if necessary) .Net
# You can just put "Goto +2" here, in order to go to the next section/function
FunctionEnd
爲了這個工作,你必須在.onInit
功能的地方調用CheckDotNet
並確保dotnetfx35.exe
包裝在你的安裝程序中$EXEDIR
(當然你可以更換它們e參數,但是你希望)。
對於.NET的其他版本,我想唯一不同的事情將在IfKeyExists
宏觀參數指定的註冊表項(現在是{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}
)
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client" Install
那麼你應該檢查$0
。這取決於你如何。
你認爲這與其他答案相比有什麼增加?它沒有說明它應該是什麼,也沒有安裝它。 –
我曾與「DotNET.nsh」 pluging,你可以找到somwhere, 並簡單地用這個解決方案(針對.NET 4.0的問題,完整安裝 - 這我需要, 可以將其以及限制客戶端軟件包):
ClearErrors
ReadRegDWORD $0 HKLM "Software\Microsoft\Net Framework Setup\NDP\v4\Full" "Install"
IfErrors dotNet40NotFound
IntCmp $0 1 dotNet40Found
dotNet40NotFound:
Banner::show /set 76 "Installing .NET Framework 4.0" "Please wait"
File /nonfatal "tools\dotNetFx40_Full_setup.exe"
; if you don't have $TEMP already, add here:
; SetOutPath $TEMP
ExecWait "$TEMP\dotNetFx40_Full_setup.exe /passive /norestart"
Delete /REBOOTOK "$TEMP\dotNetFx40_Full_setup.exe"
Banner::destroy
dotNet40Found:
旗幟的東西是可選的,你可以只使用DetailPrint
等。 通過這種方式,您可以使用.NET 4.0的Web安裝程序,但是它的尺寸很小,爲 (與沒有.NET版本的版本相反)。如果需要的話,安裝程序會下載 ,而且您不需要數公里的NSIS代碼。
可能不是正確的理由,但這個腳本代碼對我來說比其他任何示例更有意義。謝謝。 –
嘗試DotNetVer腳本。它使用LogicLib並且非常易於使用。
- HasDotNet <版本,如果>檢查安裝了.NET框架的特定版本。 <版本>可以替換爲以下值:1.0,1.1,2.0,3.0,3.5,4.0。
- AtLeastDotNetServicePack檢查.NET框架是否至少具有指定的服務包版本。
- IsDotNetServicePack檢查.NET框架是否具有完全按照指定的服務包版本。
- HasDotNetClientProfile檢查.NET框架是否爲客戶端配置文件安裝。
- HasDotNetFullProfile檢查是否。NET框架是一個完整的安裝。
樣品:
${If} ${HasDotNet4.0} DetailPrint "Microsoft .NET Framework 4.0 installed." ${If} ${DOTNETVER_4_0} AtLeastDotNetServicePack 1 DetailPrint "Microsoft .NET Framework 4.0 is at least SP1." ${Else} DetailPrint "Microsoft .NET Framework 4.0 SP1 not installed." ${EndIf} ${If} ${DOTNETVER_4_0} HasDotNetClientProfile 1 DetailPrint "Microsoft .NET Framework 4.0 (Client Profile) available." ${EndIf} ${If} ${DOTNETVER_4_0} HasDotNetFullProfile 1 DetailPrint "Microsoft .NET Framework 4.0 (Full Profile) available." ${EndIf} ${If} ${DOTNETVER_4_0} HasDotNetFullProfile 0 DetailPrint "Microsoft .NET Framework 4.0 (Full Profile) not available." ${EndIf} ${EndIf}
- 1. NSIS檢查安裝的應用程序
- 2. 使用.NET 4.0的NSIS安裝程序
- 3. .NET Framework 4.0 - 最小的安裝程序?
- 4. 查找最大Drive,NSIS安裝程序
- 5. 安裝.NET Framework
- 6. .Net Framework安裝
- 7. .NET Framework - 安裝應用程序
- 8. NSIS雙模式安裝程序。檢查路徑的有效性
- 9. 檢查NSIS安裝程序的單個實例
- 10. NSIS安裝程序名稱
- 11. NSIS安裝程序重建
- 12. .Net Framework 4.0安裝程序是否包含.Net Framework 3.5?
- 13. 從「程序和功能」啓用.Net Framework 3.5 SP1並使用NSIS進行安裝
- 14. NSIS安裝與.NET 4.5
- 15. 自定義安裝程序需要檢測.NET Framework
- 16. NSIS安裝程序 - 定義安裝程序和系統x32/x64
- 17. 查找安裝MSVC與NSIS安裝程序?
- 18. 如果未安裝.Net Framework,請運行安裝程序
- 19. Installer未利用NSIS創建安裝程序爲我的應用程序檢測到舊版本安裝NSIS
- 20. CPack NSIS,爲Windows生成安裝程序
- 21. 從NSIS安裝程序調用ngen
- 22. NSIS - 重建安裝程序exe文件
- 23. NSIS:檢測Tomcat安裝
- 24. 基於zip的NSIS安裝程序?
- 25. 調試NSIS安裝程序的方法?
- 26. 如何檢查Net 4 Framework的正確安裝?
- 27. 使用.Net 2008應用程序自動安裝.NET Framework 3.5 SP1
- 28. 如何檢測啓動帶參數的NSIS安裝程序
- 29. 在Linux上籤署NSIS安裝程序
- 30. NSIS - 複製安裝程序本身
嗯,我也對此感興趣! –
[NSIS wiki](http://nsis.sourceforge.net/Main_Page)中有幾個例子。試試[這一個](http://nsis.sourceforge.net/DotNET)。 –
這裏是檢查哪個版本安裝的方法嘗試http://forums.winamp.com/showthread.php?t=324928 – dastanko