2009-09-18 11 views
14

के लिए जांचता है, मैं एक एनएसआईएस इंस्टॉलर बनाना चाहता हूं जो .NET Framework के लिए जांचता है और यदि यह वहां नहीं है तो इसे इंस्टॉल करता है। क्या आप मुझे इसके लिए एक स्क्रिप्ट पर इंगित कर सकते हैं? मैं एनएसआईएस के लिए बहुत नया हूं।एनएसआईएस इंस्टॉलर जो .NET Framework

+0

हम्म, मुझे इसमें भी रूचि है! –

+0

[एनएसआईएस विकी] (http://nsis.sourceforge.net/Main_Page) में कई उदाहरण हैं। कोशिश करें [यह एक] (http://nsis.sourceforge.net/DotNET)। –

+0

यह देखने का तरीका है कि कौन सा संस्करण इंस्टॉल किया गया है, इसे आजमाएं http://forums.winamp.com/showthread.php?t=324928 – dastanko

उत्तर

2
!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 
0

निम्नलिखित कोड जांचता है कि .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 में पैक किया गया है (बेशक आप इसे बदल सकते हैं ई पैरामीटर हालांकि आप चाहते हैं)।

नेट के अन्य संस्करणों के लिए, मुझे लगता है कि केवल अलग बात IfKeyExists मैक्रो पैरामीटर में निर्दिष्ट रजिस्ट्री कुंजी हो जाएगा (अब यह {CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9} है)

-1
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client" Install 

तो फिर तुम $0 जांच होनी चाहिए। यह आप पर निर्भर करता है।

+0

क्या आप मानते हैं कि यह अन्य उत्तरों की तुलना में जोड़ता है? यह नहीं कहता कि यह क्या होना चाहिए, न ही यह इसे स्थापित करने जा रहा है। –

3

मैं "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 के लिए वेब इंस्टॉलर के साथ खींचते हैं, लेकिन यह बहुत छोटा है (जैसा कि .NET संस्करणों के विपरीत है जिसमें एक नहीं था)। यदि आवश्यक हो तो इंस्टॉलर डाउनलोड करता है, और आपको एनएसआईएस कोड के किलोमीटर की आवश्यकता नहीं है।

+0

संभवतः एक अपवॉट के लिए सही कारण नहीं है, लेकिन ऐसा करने के लिए इस स्क्रिप्ट कोड ने मुझे किसी अन्य उदाहरण की तुलना में अधिक समझदारी दी है। धन्यवाद। –

7

DotNetVer स्क्रिप्ट का प्रयास करें। यह LogicLib का उपयोग करता है और उपयोग करने में काफी आसान है।

  • HasDotNet < संस्करण > जांच करता है कि नेट ढांचे के विशेष संस्करण स्थापित किया गया है। < संस्करण > को निम्न मानों के साथ प्रतिस्थापित किया जा सकता है: 1.0, 1.1, 2.0, 3.0, 3.5, 4.0।
  • AtLeastDotNetServicePack जांचता है कि .NET Framework में कम से कम निर्दिष्ट सर्विस पैक संस्करण है।
  • IsDotNetServicePack जांचता है कि .NET Framework में एक सर्विस पैक संस्करण बिल्कुल निर्दिष्ट है या नहीं।
  • HasDotNetClientProfile जांचता है कि .NET ढांचा एक ग्राहक प्रोफाइल स्थापित है या नहीं।
  • HasDotNetFullProfile जांचता है कि क्या।नेट फ्रेमवर्क एक पूर्ण स्थापित है।

नमूना:

 
${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} 
0

आप .net ढांचे के साथ विकल्पों की तलाश में हैं 4.0+ (और ऊपर) सहित

  • .net 4.5
  • .net 4.5.1

एनएसआईएस के लिए इस प्लग-इन की जांच करें: DotNetChecker