Archive: trying to enable IIS with dism.exe within nsis install


trying to enable IIS with dism.exe within nsis install
Hi
I am using nsis to do an install on a Windows 7 system. I have lots of the install working, but I can't seem to get this last part working. I need to enable Windows Authentication in IIS.

When I run this command outside of the installer, it works perfectly:
C:\Windows\system32\dism.exe /online /norestart /logpath:"C:\bwm\log.etw.txt" /enable-feature /ignorecheck /featurename:"IIS-WebServerRole" /featurename:"IIS-WebServer" /featurename:"IIS-Security" /featurename:"IIS-BasicAuthentication" /featurename:"IIS-WindowsAuthentication" /featurename:"IIS-DigestAuthentication

When I put this command into a file called iisconfig.cmd and use the following code within my .nsi file, it does not work.
file iisconfig.cmd
ExecCmd::exec /TIMEOUT=40000 '"$INSTDIR\iisconfig.cmd"'
Pop $0
MessageBox MB_OK "Exit code $0"


When I try to execute the command using ExecWait, it fails to se the proper IIS items:
ExecWait 'cmd /c C:\Windows\system32\dism.exe /online /norestart /logpath:"C:\bwm\log.etw.txt" /enable-feature /ignorecheck /featurename:"IIS-WebServerRole" /featurename:"IIS-WebServer" /featurename:"IIS-Security" /featurename:"IIS-BasicAuthentication" /featurename:"IIS-WindowsAuthentication" /featurename:"IIS-DigestAuthentication"'

I've read many comments about ExecWait not waiting, bit the solutions that were provided did not solve this problem.


Have you disabled file system redirection?

Stu


Hi Stu

I looked into this since I'mnot sure what this means. This is my first time ever using install software on Windows.

I changed all of my script references from C:\Windows to %windir% since that seemed to have something to do with filesystem redirection and my windows IT guy said that I should use %windir%

That did not seem to help.

Why would disabling filesystem redirection help ? How exactly do I do that ?

Thanks Dave


Sorry, I meant the macro in x64.nsh: ${DisableX64FSRedirection}. Because NSIS is 32-bit, Windows will redirect it to C:\Windows\SysWOW64 which is probably not where your dism.exe is (assuming it is a 64-bit executable).

Stu


Hi Stu - I think you nailed the problem - many thanks ! ! ! I tried running DISM manually in SysWOW64 and System32 and it only runs in System32. Now how exactly do I Disablex64FSredireciton ? I tried adding it to the top of my script as ${DisableX64FSRedirection} but it failed to compile.


You put it in the section or function that you are calling your app from. It's a run-time call to the Wow64EnableWow64FsRedirection API. It only works for the current thread too so keep that in mind (e.g. sections run in a different thread to the callbacks such as .onInit for example).

Stu


thanks Stu, these are the three lines that I have in my .nsi file -

${DisableX64FSRedirection}

ExecWait 'cmd /c %windir%\system32\dism.exe /online /norestart /logpath:"C:\bwm\log.etw.txt" /enable-feature /ignorecheck /featurename:"IIS-WebServerRole" /featurename:"IIS-WebServer" /featurename:"IIS-Security" /featurename:"IIS-BasicAuthentication" /featurename:"IIS-WindowsAuthentication" /featurename:"IIS-DigestAuthentication"'

${EnableX64FSRedirection}


For some reason, it doesn't compile ?
Dave


You might want to supply us with the compilation error, so we know what to look for.

You need to use $WINDIR, instead of %windir%. Also you shouldn't just call 'cmd', as that could be anything. You need to execute %comspec%, so like this:

ExpandEnvStrings $0 "%COMSPEC%"
ExecWait '$0 /foo /bar'


Hi

Thanks for the suggestions! I am really new to installation software, so I welcome any and all changes you could recommend to this script. I'm basically installing components on a Windows 7 system to connect my php scripts to SQL Server and IIS.


The error I got during compilation was

Invalid command: ${DisableX64FSRedirection}
Error in script


Here's my entire nsi file...


Function .onInit
SetOutPath $TEMP
File /oname=spltmp.bmp "ExaGridLogo.bmp"
advsplash::show 10 1000 2000 0xFFFFFE $TEMP\spltmp
Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normally, and '-1' if some error occurred.
Delete $TEMP\spltmp.bmp
FunctionEnd

name "Backup Window Manager 1.0"

# ------------------------------------------------------
#
# define installer name
outFile "BWM_installer.exe"

# set default install directory
InstallDir c:\bwm

# Request application privileges for Windows Vista
RequestExecutionLevel admin

# --------------------------------------------------------
#
# Pages

# Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

# --------------------------------------------------------
#
# default section start
section

# define output path
setOutPath $INSTDIR

# specify file to go in output path

# --- php ---
file php-5.3.6-nts-Win32-VC9-x86.msi
ExecWait '"msiexec.exe" /i "$INSTDIR\php-5.3.6-nts-Win32-VC9-x86.msi" /qn'

# --- Microsoft Visual C++ 2008 Redistributable Package (x86)
file vcredist_x86.exe
ExecWait '"$INSTDIR\Vcredist_x86.exe" /q:a /c:msiexec /i "vcredist.msi" /qn /l*v "%temp%\vcredist_x86.log"'

# TODO: may need to support both x86 and x64 in real install!!!
# --- php Manager for IIS
file PHPManagerForIIS-1.1.2-x64.msi
ExecWait '"msiexec.exe" /i "$INSTDIR\PHPManagerForIIS-1.1.2-x64.msi" /qn'

# TODO: may need to support both x86 and x64 in real install!!!
# --- SQL Server Native Client
file sqlncli.msi
ExecWait '"msiexec.exe" /i "$INSTDIR\sqlncli.msi" IACCEPTSQLNCLILICENSETERMS=YES /qn'

# --- sqlsrv_* access to BackupExec SQL Server database from php
file SQLServerDriverForPHP11.EXE
ExecWait '"$INSTDIR\SQLServerDriverForPHP11.EXE" /C /T:$INSTDIR /Q'

CopyFiles $INSTDIR\php_sqlsrv_53_nts_vc9.dll "C:\Program Files (x86)\PHP\ext"

# --- overwrite the EDITED php.ini file
file php.ini
CopyFiles $INSTDIR\php.ini "C:\Program Files (x86)\PHP"

# --- copy the php_cgi.exe file
file php-cgi.exe
CopyFiles $INSTDIR\php-cgi.exe "C:\Program Files (x86)\PHP"

# --- install our own source files
file /r BWMsource\*.*

# configure IIS - create BWM web site
ExecWait '%windir%\system32\inetsrv\appcmd.exe add site /name:BackupWindowManager /bindings:http/*:80: /physicalPath:c:\bwm'

# --------------------------------------------------------
# --- TODO - we need to used DISM to turn on
# Windows Authentication so that we can then
# enable it later in the script.
# THE ExecWait DOESN'T WAIT LIKE IT SHOULD
#

${DisableX64FSRedirection}

ExecWait 'cmd /c %windir%\system32\dism.exe /online /norestart /logpath:"C:\bwm\log.etw.txt" /enable-feature /ignorecheck /featurename:"IIS-WebServerRole" /featurename:"IIS-WebServer" /featurename:"IIS-Security" /featurename:"IIS-BasicAuthentication" /featurename:"IIS-WindowsAuthentication" /featurename:"IIS-DigestAuthentication"'

${EnableX64FSRedirection}

#
# --------------------------------------------------------


# configure IIS - enable windowsauthentication
# disable anonymous and digest authentication

ExecWait '%windir%\system32\inetsrv\appcmd.exe set config BackupWindowManager -section:system.webServer/security/authentication/anonymousAuthentication /enabled:False /commit:apphost'

ExecWait '%windir%\system32\inetsrv\appcmd.exe set config BackupWindowManager -section:system.webServer/security/authentication/windowsAuthentication /enabled:True /commit:apphost'

ExecWait '%windir%\system32\inetsrv\appcmd.exe set config BackupWindowManager -section:system.webServer/security/authentication/digestAuthentication /enabled:False /commit:apphost'

# create IIS - FastCGI process pool
ExecWait '%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+"[fullPath=c:\Program Files (x86)\PHP\php-cgi.exe]"'
ExecWait '%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/handlers /+"[name=PHP-FastCGI,path=*.php,verb=GET,HEAD,POST,modules=FastCgiModule,scriptProcessor=C:\Program Files (x86)\PHP\php-cgi.exe,resourceType=Either,requireAccess=Script]"'

# -----------------------------------------------------------
#
# define uninstaller name
writeUninstaller $INSTDIR\BWM_uninstaller.exe

# default section end
sectionEnd


# create a section to define what the uninstaller does.
# the section will always be named "Uninstall"
section "Uninstall"

# Always delete uninstaller first
delete $INSTDIR\BWM_uninstaller.exe

ExecWait '"msiexec.exe" /uninstall "$INSTDIR\php-5.3.6-nts-Win32-VC9-x86.msi" /qn'

ExecWait '"msiexec" /uninstall "$INSTDIR\sqlncli.msi" /qn'

ExecWait '"msiexec" /uninstall "$INSTDIR\PHPManagerForIIS-1.1.2-x64.msi" /qn'

ExecWait '"msiexec" /uninstall "vc_red.msi" /qn'

# now delete installed file
delete $INSTDIR\php-5.3.6-nts-Win32-VC9-x86.msi
delete $INSTDIR\vcredist_x86.exe
delete $INSTDIR\SQLServerDriverForPHP11.EXE
delete $INSTDIR\PHPManagerForIIS-1.1.2-x86.msi
delete $INSTDIR\PHPManagerForIIS-1.1.2-x64.msi
delete $INSTDIR\sqlncli.msi
delete $INSTDIR\php_sqlsrv_*.*
delete $INSTDIR\php.ini
delete $INSTDIR\SQLServerDriver*.*
rmdir $INSTDIR
sectionEnd


(Please use http://nsis.pastebin.com to paste large amounts of code, or add your script file as an attachment.)

To use the x64 defines, you need to first !include the appropriate nsh file:
!include x64.nsh


Hey MSG - thanks for the advice. That solved my problem. Sorry about the long post. I'm new to all of this and did not know better.