lievencardoen
10th May 2006 09:34 UTC
FileOpen - Help
I have this piece of code :
FileOpen $3 $0\login.xml w
IfErrors 0 +3
MessageBox MB_OK "Could not write to network destination. See if you have proper rights."
Abort
StrCpy $4 "<users></users>"
FileWrite $3 $4
FileClose $3
No, when I choose a network destination (mapped network drive), I get the message "Could not write to network destination...". So, normally, you should think that login.xml is not created. But it is. A login.xml file is created, but <users></users> is not written into it...
Why is this?
thx, Lieven Cardoen
RobGrant
10th May 2006 09:40 UTC
Where is this code placed? Abort only works inside a function, I think. If it's just in a section, you probably need to do this:
FileOpen $3 $0\login.xml w
IfErrors writeerror
StrCpy $4 "<users></users>"
FileWrite $3 $4
FileClose $3
Goto writeend
writeerror:
MessageBox MB_OK "Could not write to network destination. See if you have proper rights."
writeend:
Or something...
RobGrant
10th May 2006 09:42 UTC
Actually, this is slightly neater:
FileOpen $3 $0\login.xml w
IfErrors 0 +3
MessageBox MB_OK "Could not write to network destination. See if you have proper rights."
Goto writeend
StrCpy $4 "<users></users>"
FileWrite $3 $4
FileClose $3
writeend:
RobGrant
10th May 2006 09:43 UTC
And while I'm bumping up massive amounts of posts just on this one thread, make sure you call ClearErrors at the start, otherwise IfErrors could just be picking up an old error.
lievencardoen
10th May 2006 09:43 UTC
Well, it's inside a function so I don't think it has something to do with that...
thx
lievencardoen
10th May 2006 09:52 UTC
Anyway, I need to abort so that nsis doesn't move on to next dialog...
I changed my code to
IfFileExists $0\login.xml +8 0
FileOpen $3 $0\login.xml w
StrCpy $4 "<users></users>"
FileWrite $3 $4
FileClose $3
IfErrors 0 +3
MessageBox MB_OK "Could not write to network destination. See if you have proper rights."
Abort
It doesn't make a lot of sense but what happens is this. The file login.xml is created, the xml is written to it and then the MessageBox is shown... but why, there doesn't seem to be any problem...
lievencardoen
10th May 2006 09:55 UTC
I guess ClearErrors is a usefull command. Apparently this was the problem...
Thx, guys, for the feedback!