DirectX Installation with Web Installer
From NSIS Wiki
The following is for NSIS installations that need DirectX and you assume the user to be connected to the Internet. While this isn't completely full-proof, it's better than adding over 100mb to your install file.
For off-line installers, especially when distributed via DVD, CD-ROM or other fixed media, see DirectX Installation for Fixed Media.
Obtain the latest DirectX End-User Runtime Web Installer from Microsoft. It's very small as it dynamically pulls the content it needs when run.
This script also assumes the NSIS installer is requesting Admin privileges in the form of RequestExecutionLevel admin.
About the Web Installer
When you run the Web installer, the installer will do the following:
- Examine the user's current DirectX install.
- Obtain a list of all available DirectX files from the Microsoft servers.
- Compare the local install with the latest available.
- Download files not existent on the user computer.
- Install the new files.
- Clean up the existing DirectX install.
The obvious flaw is when a user has unreliable Internet access. The web installer isn't very smart and will take a long time to exit if the Internet doesn't exist for the end user. You will need to introduce messaging to the user that explains the update will work best with Internet access.
The process of using the web installer is the following:
- Copy the Web Installer onto the user's TEMP folder.
- Run the installer from the TEMP folder.
- Wait till DirectX is done updating.
- Remove the locally stored installer from the TEMP folder.
To start, you will need to declare the following variable early in the NSIS script:
To make things easier on yourself, create a new Section for DirectX. NSIS will run the section while installing. The placement of the section could go anywhere, but it's highly recommended that DirectX be the last install section after everything else is complete. This is incase DirectX fails, your software will be installed.
If you use component install UI, DirectX will show up as an entry. You can force on with "SectionIn RO", or leave out if you wish the user to have the option to run the DirectX install.
Section "DirectX Install" SEC_DIRECTX SectionIn RO SetOutPath "$TEMP" File "dxwebsetup.exe" DetailPrint "Running DirectX Setup..." ExecWait '"$TEMP\dxwebsetup.exe" /Q' $DirectXSetupError DetailPrint "Finished DirectX Setup" Delete "$TEMP\dxwebsetup.exe" SetOutPath "$INSTDIR" SectionEnd
Note: I redeclare the SetOutPath to $INSTDIR. This way shortcuts and other functions using SetOutPath won't get messed up. Alter this line accordingly.
The variable $DirectXSetupError is used to force NSIS to pause while the DirectX setup is running. You can use the error code to further script error handling, but a variable is required to be there in order for NSIS to wait.
I've also included DetailPrint lines to display the DirectX status in the install logs. These strings can be localized to your liking.