
Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Hi, Mattias!
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool CheckTokenMembership(IntPtr TokenHandle, IntPtr
SidToCheck, out bool IsMember);
bool b = false ;
IntPtr TokenHandle = IntPtr.Zero;
IntPtr AdministratorsGroup is correct and equal "S-1-5-32-544" ( admin
group ) when I used
ConvertSidToStringSid() to see result of AllocateAndInitializeSid()
if (!CheckTokenMembership(TokenHandle, AdministratorsGroup, out b)) return
me true where C++ code return false ( as I wrote b return correct false for
such user )
TIA
Arkady
>>My question why interop change return code from false to true ?
>
> Without seeing any of your code, my guess will have to be that you've
> declared the function incorrectly.
>
> Mattias
Arkady Frenkel - 10 Jan 2007 07:31 GMT
In advance additional a liitle bit strange ( at least for me ) with interop
was before when I received SID of admin group :
I set
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool AllocateAndInitializeSid(
ref byte[] pIdentifierAuthority,byte nSubAuthorityCount,
int dwSubAuthority0, int dwSubAuthority1,int dwSubAuthority2, int
dwSubAuthority3,
int dwSubAuthority4, int dwSubAuthority5, int dwSubAuthority6, int
dwSubAuthority7,
out IntPtr pSid);
and call it
byte[] SECURITY_NT_AUTHORITY = {0,0,0,0,0,5} ;
bool b = AllocateAndInitializeSid(ref SECURITY_NT_AUTHORITY, ...
return pSid was wrong something like S-1-123456-1 OTOH when I changed
declaration to ref byte pIdentifierAuthority instead of byte[] and call
bool b = AllocateAndInitializeSid(ref SECURITY_NT_AUTHORITY[0],
correct S-1-5-32-544 returned
TIA
Arkady
> Hi, Mattias!
> [DllImport("advapi32.dll", SetLastError = true)]
[quoted text clipped - 25 lines]
>>
>> Mattias