Archive: how to get system drive letter


how to get system drive letter
  Hi, how can I get the system drive letter to complete this InstallDir "_:\MyFolder\"

I know that 'ReadEnvStr $0 SYSTEMDRIVE' can do it but only in 'Section or Function'. So the 'InstallDir' is in declaration.

Thank you!

Guillaume


you can put it on the .onInit Function.

I've created a page so the user can choose the drive in which he wants to install. like this (showing only relevant parts):


"FileFunc.nsh"

>!insertmacro GetDrives

>Var drives

>Function .onInit
StrCpy $drives ""
${GetDrives} "HDD" "GenerateDrivesString"
File /oname=$PLUGINSDIRDrive.ini "Drive.ini"
WriteINIStr "$PLUGINSDIR\\Drive.ini" "Field 2" "ListItems" "$drives"
>FunctionEnd

>Function GenerateDrivesString
StrCmp $drives"" 0 +2
StrCpy $drivesState "$9"
StrCmp $drives "" +2
StrCpy $drives "$drives|"
StrCpy $drives "$drives$9"
Push $0
FunctionEnd


>Function ShowDrive
WriteINIStr "$PLUGINSDIR\\Drive.ini" "Field 1" "Text" "Select drive"
InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\\Drive.ini"
Pop $0
InstallOptions
::show
Pop$0
FunctionEnd

>Function LeaveDrive
ReadINIStr$0 "$PLUGINSDIR\\Drive.ini" "Field 2" "State"
StrCpy $INSTDIR "$0\\MyDirectory"
>FunctionEnd
>
and, of course, you need the Drive.ini file

[Settings]
NumFields=2

[Field 1]
Type=Label
Text=Select which drive to install
Left=84
Right=256
Top=49
Bottom=57

[Field 2]
Type=DropList
Text=DropList
State=C:
ListItems=A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:
Left=84
Right=212
Top=62
Bottom=76


Hi, when I compile there are an error on this line 'File /oname=$PLUGINSDIR\Drive.ini Drive.ini' (File: "Drive.ini" -> no files found.) So I search on Web but there are nothing interesting to solve this problem.

Thank you

Guillaume


You need to create a file called Drive.ini with the following contents and put it in the same folder of your .nsi script.

Originally posted by rsvargas


[Settings]
NumFields=2

[Field 1]
Type=Label
Text=Select which drive to install
Left=84
Right=256
Top=49
Bottom=57

[Field 2]
Type=DropList
Text=DropList
State=C:
ListItems=A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:
Left=84
Right=212
Top=62
Bottom=76


Greet but I have another stupid error in this line 'StrCpy $drivesState "$9" ' (Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]). So what I have to do to solve this?!

Thank you again

Guillaume


You need to declare the variable, you can add


drivesState 

>
just below the line with

drives 

>
Or you can just delete the line which refers to this variable...

Okay, but in 'InstallDir "_\imagem\PSadmin\"' (at declaration what I have to put in '_' to have the right drive letter?)


Just use a variable in InstallDir.

Var SystemDrive
InstallDir `$SystemDrive\some\dir`

You just have to use ReadEnvStr $SystemDrive SYSTEMDRIVE in .onInit.

Stu


It didn't work, there are no letter it appear like that: /my/folder


Can you post the portion of your code that try to fetch the drive letter?



"NAME"

>!define APPNAMEANDVERSION "VERSION"

>Var SystemDrive

>; Main Install settings
Name "${APPNAMEANDVERSION}"
>InstallDir "$SystemDrive\\MY\\PATH\"
InstallDirRegKey HKLM "
Software${APPNAME}" ""
OutFile "C:Install.exe"
!define PROGPATH "$SystemDriveMY"

RequestExecutionLevel admin

; Modern interface settings
!include "MUI.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"

; MUI Welcome page on 3 lines
!define MUI_WELCOMEPAGE_TITLE_3LINES

; MUI Settings / Icons
!define MUI_ICON "${NSISDIR}ContribGraphicsEntIconsEnt.ico"
!define MUI_UNICON "${NSISDIR}ContribGraphicsEntIconsEnt.ico"

; MUI Settings / Header
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_RIGHT
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}ContribGraphicsEntHeaderHeader.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}ContribGraphicsEntHeaderHeader.bmp"

; MUI Settings / Wizard
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}ContribGraphicsEntWizardWizard.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${NSISDIR}ContribGraphicsEntWizardWizard.bmp"

;!define MUI_WELCOMEPAGE_TITLE '${WELCOME_TITLE}'
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; Set languages (first is default language)
;!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_RESERVEFILE_LANGDLL

!insertmacro GetDrives

; ******************************************************************************************************
; * INSTALL
; ******************************************************************************************************
Section "NAME" Section1

; Set Section properties
SetOverwrite on

; Set Section Files and Shortcuts
SetOutPath "$INSTDIR"
File "..Name.exe"
File "..LIB.jar"

SetOutPath "$INSTDIRimages"
File "..images*.*";

SetOutPath "$INSTDIRimages_icons"
File "..imagesicons*.*";

SetOutPath "$INSTDIRimagesright"
File "..imagesright*.*";

SetOutPath "$INSTDIRlang"
File "..langfr.xml"

SetOutPath "$INSTDIRreports"
File "..reports*.rpt"

SetOutPath "$INSTDIRtmp"

; menu démarrer
CreateDirectory "$SMPROGRAMSMYPATH"
CreateShortCut "$SMPROGRAMSMYPATHNAME.lnk" "$INSTDIRNAME.exe"
CreateShortCut "$SMPROGRAMSMYPATHUninstall.lnk" "$INSTDIRuninstall.exe"

SectionEnd

; ******************************************************************************************************
; * FINISH SECTION
; ******************************************************************************************************
Section -FinishSection

WriteRegStr HKLM "Software${APPNAME}" "" "$INSTDIR"
WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstall${APPNAME}" "DisplayName" "${APPNAME}"
WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstall${APPNAME}" "UninstallString" "$INSTDIRuninstall.exe"

WriteUninstaller "$INSTDIRuninstall.exe"

SectionEnd

; Modern install component descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Section1} "Jesus love bacon"
!insertmacro MUI_FUNCTION_DESCRIPTION_END

; ******************************************************************************************************
; * UNINSTALL
; ******************************************************************************************************
Section Uninstall

;Remove from registry...
DeleteRegKey HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstall${APPNAME}"
DeleteRegKey HKLM "SOFTWARE${APPNAME}"

;Remove the Main Folder
RMDir /r "$INSTDIR"
RMDir "${IMAGEMPATH}"

; Delete Shortcuts
Delete "$SMPROGRAMSMYPATHNAME.lnk"
Delete "$SMPROGRAMSMYPATHUninstall.lnk"

RMDir "$SMPROGRAMSMYPATH"
RMDir "$SMPROGRAMSMY"
SectionEnd

Function .onInit
ReadEnvStr $SystemDrive SYSTEMDRIVE
FunctionEnd
>
When I Install the program, in Installation folde it write: \MY\PATH, so I when the lettre _:\MY\PATH

Thank yout guys

PS: there are missing somes "\" just don't take care about it

Guillaume

Try moving the


InstallDir "$SystemDrive\MY\PATH\" 

>
statement to the .onInit function. The .onInit function should be like this:


onInit 

ReadEnvStr $SystemDrive SYSTEMDRIVE
InstallDir "$SystemDrive\\MY\\PATH\\"
>FunctionEnd
>

You're right. InstallDir is being evaluated while $SystemDrive is still empty.

Instead just use this in .onInit:

Function .onInit
ReadEnvStr $R0 SYSTEMDRIVE
StrCpy $INSTDIR `$R0\MY\PATH\`
FunctionEnd


@ rsvargas:
InstallDir is a compile time instruction. It is not valid within a Function or Section.

Stu

@Afrow UK
My bad, I use the StrCpy $INSTDIR way to set the directory in my installers, and didn't remember that the InstallDir directive would not work in a function, thanks!


Thank you really much Afrow UK :D