Archive: copying files to HOMEPATH


copying files to HOMEPATH
hey there,

i've got to install a java development package including some ant targets.
These ant targets have to be installed at %HOMEPATH%/.ant/lib.

my function looks that way


;--------------------------------
; --- Installieren der Ant-Tasks
;
; Returnwerte:
; 0 für fehlerfreie Ausführung
; 1 für fehlende Umgebungsvariablen
;
; Aufruf:
; Call copyAntTasks
; Pop $R0
; IntCmp $R0 0 lbl_CopyAnt_OK
; ; Fehlerbehandlung
; lbl_CopyAnt_OK:
; ; Weiter
;
Function copyAntTasks

; Hole das Benutzer-Homeverzeichnis und breche bei Fehlern ab.
ClearErrors
ReadRegStr $R1 HKCU "Volatile Environment" "HOMEPATH"
IfErrors 0 lbl_environment_geholt
Push "1"
Goto lbl_copyAntTasks_ende


; lbl_environment_geholt:
; ; Ant-Homeverzeichnis prüfen und ggf. erstellen
; IfFileExists $R1\.ant lbl_antdir_exists
; CreateDirectory $R1\.ant

; lbl_antdir_exists:
; ; Ant-Libverzeichnis prüfen und ggf. erstellen
; IfFileExists $R1\.ant\lib lbl_antlib_exists
; CreateDirectory $R1\.ant\lib

lbl_antlib_exists:
; Ant-Tasks kopieren
SetOutPath $R1; C:\temp
File /r d:\install_jade\ant\*.*
; Exec '"COPY c:\temp\.ant %HOMEPATH%"'
Push "0"

lbl_copyAntTasks_ende:
FunctionEnd


This function should be able to copy my files but it doesn't! I always get a write error while testing the install file.

As you can see, I tried to copy by a shell copy, too but this didn't work at all. A copy "by hand" works, HOMEPATH doesn't seem to be write protected.

Is it possible to set/unset a writ protection via nsis?

what am I doing wrong?

%HOMEPATH% doesn't have drive specified in it. So you should use %HOMEDRIVE%%HOMEPATH% to get the full path.

Also I recommend that you use ReadEnvStr instruction instead of ReadRegStr to get the environment variables. Not that there's nothing wrong in the ReadRegStr method, but ReadEnvStr uses the proper APIs to get the environment variable.


Copy is an internal command built into CMD.exe and Command.com. Exec needs an actual file. That's probably why EXEC doesn't work for you. You could call it by saying

ReadEnvStr $0 COMSPEC
ReadEnvStr $1 HOMEPATH
ExecWait '"$0" /c copy c:\temp\.ant "$1"'

whats wrong with CopyFiles ?


Why not use $PROFILE?


well, after solving some problems (concatenating two strings) I got it :)
here's the code- if so needs

[code]
;--------------------------------
; --- Installieren der Ant-Tasks
;
; Returnwerte:
; 0 für fehlerfreie Ausführung
; 1 für fehlende Umgebungsvariablen
;
; Aufruf:
; Call copyAntTasks
; Pop $R0
; IntCmp $R0 0 lbl_CopyAnt_OK
; ; Fehlerbehandlung
; lbl_CopyAnt_OK:
; ; Weiter
;
Function copyAntTasks
; Hole das Benutzer-Homelaufwerk und breche bei Fehlern ab.
ClearErrors
ReadEnvStr $R2 "HOMEDRIVE"
IfErrors 0 lbl_homedir_geholt
DetailPrint "HOMEDRIVE nicht lesbar"
Push "1"
Goto lbl_copyAntTasks_ende

lbl_homedir_geholt:
; Hole das Benutzer-Homeverzeichnis und breche bei Fehlern ab.
ClearErrors
ReadEnvStr $R3 "HOMEPATH"
IfErrors 0 lbl_homepath_geholt
DetailPrint "HOMEPATH nicht lesbar"
Push "1"
Goto lbl_copyAntTasks_ende

lbl_homepath_geholt:
; Ant-Tasks kopieren
${StrCat} $R2 $R3 $R1

DetailPrint "Kopiere Ant-Tasks nach $R1"

SetOutPath $R1
File /r d:\install_jade\ant\*.*
; Exec '"COPY c:\temp\.ant %HOMEPATH%"'
Push "0"

lbl_copyAntTasks_ende:
FunctionEnd
[code]

the macro is described here

thanks for helping :)


I ask again - why use environment variables when you have $PROFILE?