Reprinted from: http://www.flighty.cn/html/bushu/20140704_239.html
now we want to implement this feature:If the target machine has a D drive, install the program to D, or install it on the system disk. It was later added that the registry would use its key value as the installation path if an installation path key value existed.
Ideas:By checking that the D disk has no disk space to judge, if the D drive does not exist, or if the D drive is an optical drive, the resulting disk space must be null.
Example:
!include"Mui2.nsh"!include"Filefunc.nsh"Requestexecutionlevel AdminName"determine the presence or absence of the D disk determining the installation path"Caption"determine the presence or absence of the D disk determining the installation path"OutFile"Test.exe"InstallDir"$PROGRAMFILES \flighty App"read the installation path in the registration, and then follow the default path if it does not exist. Installdirregkey HKCU"software\flighty App" ""Brandingtext"www.flighty.cn"!insertmacro mui_page_directory!insertmacro mui_page_instfiles!insertmacro mui_language"Simpchinese"sectionsectionendsection-Post; Write the installation path in the registry Writeregstr HKCU"software\flighty App" ""$INSTDIRSectionEndFunction. OnInit readregstr $R 4 HKCU"software\flighty App" ""STRCMP $R 4""NO YES no:strcpy $R 1"d:\ "${drivespace} $R 1"/d=f/s=m"$R 0 ${if} $R 0=null StrCpy $R 1"$PROGRAMFILES \flighty App"${else} StrCpy $R 2"Program Files"StrCpy $R 3"flighty app"StrCpy $R 1"d:\ $R 2\ $R 3"${endif}; reset $instdir default value StrCpy $INSTDIR"$R 1"Yes:goto+1FunctionEnd
Go NSIS: Determine the presence or absence of the D disk determines the installation path