SID(安全标识符)是用于标识 Windows NT 的用户帐户、组、域或计算机的安全标识符。系统使用帐户 SID 而不是他们的个人资料用户名进行操作。SID 在创建时分配给每个帐户,因此如果您要使用相同的名称和密码再次创建帐户,SID 当然会有所不同。重新创建帐户将导致生成新的 SID。它们是独一无二的,如果你拿起我放下的东西..
宏:
;=#
;= ${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
下面是一个列出主机 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}
现在我不确定这是否可行(可能是前提,但总是有 ACL),但这里有一个例子(如果我正确理解你的问题)来暗示你在问什么。
${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
这只是一个快速修复..甚至不确定这是否会奏效,但也许是您朝着正确方向迈出的一步?希望这可以帮助!