Un setup creato con Nullsoft installer che lancia l'installazione di slqexpress solo se non presente.

Ho specificato un po di opzioni che cmq si possono personalizzare (vedi ExecWait ... )

  1. OutFile "SQLExpress2005Setup.exe"
  2.  
  3. Section
  4. SectionEnd
  5.  
  6. Function .onInit
  7.    #installazione non visibile 
  8.    SetSilent silent
  9.   
  10.    # controllo presenza SQL Express 2005
  11.    Call CheckSqlExpress
  12.  
  13.    ExecWait 'SQLEXPR_ITA.EXE /qb INSTANCENAME=SQLEXPRESS \
  14.          ADDLOCAL=SQL_Engine SECURITYMODE=SQL \
  15.          SAPWD=strpwd DISABLENETWORKPROTOCOLS=0'
  16.    SetOutPath "$DESKTOP" 
  17.  
  18.    #Start /wait <CD or DVD Drive>\servers\setup.exe /qb
  19.    #INSTANCENAME=<InstanceName>
  20.    #ADDLOCAL=All
  21.    #PIDKEY=<pidkey value with no "-">
  22.    #SAPWD=<StrongPassword>
  23.    #SQLACCOUNT=<domain\user>
  24.    #SQLPASSWORD=<DomainUserPassword>
  25.    #AGTACCOUNT=<domain\user>
  26.    #AGTPASSWORD=<DomainUserPassword>
  27.    #SQLBROWSERACCOUNT=<domain\user>
  28.    #SQLBROWSERPASSWORD=<DomainUserPassword>
  29. FunctionEnd
  30.  
  31. Function CheckSqlExpress
  32.  
  33.       Call CheckSqlExpressInstalled
  34.         Pop $0
  35.         StrCmp $0 1 found.SQLExpress2005 no.SQLExpress2005
  36.   found.SQLExpress2005:
  37.        MessageBox MB_OK "SQL Express 2005 è già installato."
  38.          abort
  39.   no.SQLExpress2005:
  40. FunctionEnd
  41.  
  42. Function CheckSqlExpressInstalled
  43.  
  44.          Push $0
  45.          Push $1
  46.          Push $2
  47.          Push $3
  48.          Push $4
  49.        Push $5
  50.  
  51.          StrCpy $0 "0"
  52.          StrCpy $1 "SOFTWARE\Microsoft" ;registry entry to look in.
  53.          StrCpy $2 0
  54.  
  55.   StartEnum:
  56.         EnumRegKey $3 HKLM "$1\Microsoft SQL Server" $2
  57.  
  58.         #MessageBox MB_OK "EnumRegKey $3"
  59.         StrCmp $3 "" noSQL notEmpty
  60.  
  61.         ;Trovato qualcosa
  62.     notEmpty:
  63.         ;Inizia per 'MSSQL.'.
  64.         StrCpy $4 $3 6 0
  65.       #MessageBox MB_OK "EnumRegKey $4"
  66.         StrCmp $4 "MSSQL." +1 goNext
  67.      
  68.         ReadRegStr $5 HKLM "$1\Microsoft SQL Server\$3\Setup" "Edition"
  69.       StrCmp $5 "Express Edition" yesSQL goNext
  70.      
  71.       #MessageBox MB_OK "ok: $5"
  72.       Goto noSQL
  73.  
  74.     goNext:
  75.         ;Vado alla prossima chiave.
  76.         IntOp $2 $2 + 1
  77.         goto StartEnum
  78.    
  79.   noSQL:
  80.        #MessageBox MB_OK "NON trovato SQL Express 2005"
  81.        StrCpy $0 0
  82.        Goto done
  83.  
  84.   yesSQL:
  85.        #MessageBox MB_OK "Trovato SQL Express 2005"
  86.        StrCpy $0 1
  87.   done:
  88.       Pop $5
  89.        Pop $4
  90.        Pop $3
  91.        Pop $2
  92.        Pop $1
  93.        ;MessageBox MB_OK $0
  94.        Exch $0
  95.  
  96. FunctionEnd
  97.