SID (security identifier) is a security identifier that identifies a user account, groups, Domain or computer for Windows NT. The system operates with account SIDs, and not their profile usernames. SID is assigned to each account at the time of its creation so if you were to create an account again with the same name and password, the SID will, of course be different. The re-creation of an account will result in the generation of a new SID. They are unique, if you are picking up what I am laying down..
MACRO:
;=#
;= ${GETUSERSID} $0 "Username"
; $0 = The returning SID value
; "Username" = The username of the account you wish the SID
; If the username is an empty value, then the SID of the
; current user will be given to $0.
!define GETUSERSID "!insertmacro _GETUSERSID"
!macro _GETUSERSID _RESULT _USER
System::Store S
StrCpy $0 ${_USER}
StrCmp $0 "" 0 +2
ExpandEnvStrings $0 "%USERNAME%"
System::Call "*(&t1024)i.r1"
System::Call "advapi32::LookupAccountName(tn,tr0,ir1,*i1024,tn,*i1024,*in)i.r0"
IntCmp $0 1 0 +2 +2
System::Call "advapi32::ConvertSidToStringSid(ir1,*t.s)"
IntCmp $0 1 +2 0 0
Push error
System::Free $1
System::Store L
Pop "${_RESULT}"
!macroend
${GETUSERSID} $0 "Username"
MessageBox MB_ICONINFORMATION|MB_OK "User's SID:$\r$\n$$0 is holding $0" IDOK
Now here is an example of listing all the registered user accounts on a host PC:
System::Call "netapi32::NetQueryDisplayInformation(wn,i1,i0,i-1,i${NSIS_MAX_STRLEN},*i.R0,*i.R1)i.R4"
${If} $R4 = 0
${For} $R4 1 $R0
System::Call "*$R1(i.R2,i.R3,i,w,i,i)"
IntFmt "$R2" ${STR} $R2
IntFmt "$R3" ${STR} $R3
${GetUserSID} "$R2" "$R5"
IntOp $R1 $R1 + 24
DetailPrint "-----------------"
DetailPrint "Name: $R2"
DetailPrint "SID: $R5"
DetailPrint "$R3"
${Next}
System::Call "netapi32::NetApiBufferFree(iR1)"
${EndIf}
Now I am not sure if this will work or not (premissions maybe, but then there is always ACL) but here is an example (if I understand your issue correctly) of implimenting what you are asking.
${GETUSERSID} $0 "postgres"
ReadRegStr $1 HKU "$0\Volatile Environment" "APPDATA"
DetailPrint "APPDATA: $1"
AccessControl::GrantOnFile $1 "USER" "ListDirectory + GenericRead + GenericExecute"
AccessControl::EnableFileInheritance $1
SetOutPath "$1\postgresql"
File config\pgpass.conf
This was just a quick fix ..not even sure this will work but maybe a step in the right direction for you? Hope this helps!