My dilema with this UDF was that the user could have any number of mapped drives with the target server's name in it. If I only use the last error code, i.e.

code:
$rc=WRITEVALUE(...)
if @ERROR
$err=@ERROR
endif

...then a failed write error code could potentially be overwritten by a successful one. The only option would be to exit the UDF on any WriteValue() error.