!include "MUI2.nsh" !include "FileFunc.nsh" RequestExecutionLevel admin Name "判断D盘存在与否确定安装路径" Caption "判断D盘存在与否确定安装路径" OutFile "test.exe" InstallDir "$PROGRAMFILES\flighty app" ;读取注册中的安装路径,如果不存在则按照默认路径。 InstallDirRegKey HKCU "Software\flighty app" "" BrandingText "www.flighty.cn" !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_LANGUAGE "SimpChinese" Section SectionEnd Section -Post ;在注册表中写入安装路径 WriteRegStr HKCU "Software\flighty app" "" $INSTDIR SectionEnd Function .onInit ReadRegStr $R4 HKCU "Software\flighty app" "" StrCmp $R4 "" NO YES NO: StrCpy $R1 "D:\" ${DriveSpace} $R1 "/D=F /S=M" $R0 ${If} $R0 = null StrCpy $R1 "$PROGRAMFILES\flighty app" ${Else} StrCpy $R2 "Program Files" StrCpy $R3 "flighty app" StrCpy $R1 "D:\$R2\$R3" ${EndIf} ;重新设置$INSTDIR默认值 StrCpy $INSTDIR "$R1" YES: Goto +1 FunctionEnd |