mar. 21 septembre 2010, 09h59
Mike Gagnon
atoutfox.public.association
Re: WMI/Win32 API : trouver le 'SID' de l'utilisateur courant
Clear
Declare RtlMoveMemory In kernel32 As MemToStr;
STRING @dst, Integer src, Integer nLength
Declare Integer LocalFree In kernel32 Integer Hmem
Declare Integer GetUserName In advapi32;
STRING @lpBuffer, Integer @nSize
Declare Integer LocalAlloc In kernel32;
INTEGER uFlags, Integer uBytes
Declare Integer LookupAccountName In advapi32;
STRING lpSystemName, String lpAccountName,;
INTEGER Sid, Integer @cbSid,;
STRING @RefDomainName, Integer @cchRefDomainName,;
INTEGER @peUse
Declare Integer ConvertSidToStringSid In advapi32;
INTEGER Sid, Integer @StringSid
Declare Long LocalSize In kernel32 Integer Hmem
nSize = 250
cBuffer = Repli(Chr(0), nSize)
If GetUserName (@cBuffer, @nSize) > 0
cBuffer = Strtran(Alltrim(Substr (cBuffer, 1, nSize)), Chr(0),"")
? "User:", cBuffer
Do GetSid With cBuffer
Endif
Procedure GetSid(cAccount)
Local hSid, nSidsize, cDomain, nDomainsize, peUse
nSidsize=128
hSid=LocalAlloc(0, nSidsize)
nDomainsize=250
cDomain=Replicate(Chr(0), nDomainsize)
peUse=0
* retrieve security identifier (SID) for the account name
= LookupAccountName(Null, m.cAccount,;
hSid, @nSidsize, @cDomain, @nDomainsize, @peUse)
* convert the SID to string format
Local nBuffer, nBufsize, cSid
nBuffer=0
= ConvertSidToStringSid(hSid, @nBuffer)
nBufsize = LocalSize(nBuffer)
cSid = Replicate(Chr(0), nBufsize)
= MemToStr(@cSid, nBuffer, nBufsize)
= LocalFree(nBuffer)
= LocalFree(hSid)
? "Domain:", Substr(cDomain, 1, At(Chr(0),cDomain)-1)
? "SID:", cSid
"Thierry N" <none@zenbuyer.com> wrote in message
news:i77f4m$iq3$1@news.niouzes.net...
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000004065