Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2007

Tip: Looking for answers? Try searching our database.

CheckTokenMembership with Interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arkady Frenkel - 09 Jan 2007 16:38 GMT
Hi, dears!

When I took example of using
CheckTokenMembership() from
http://msdn2.microsoft.com/en-us/library/aa376389.aspx

to check IsUserAdmin() that work great in C++, but when I call the
CheckTokenMembership() in

csharp for user without admin rights , it returned true opposite to c++
where it return false and that what checked in example. OTOH IsMember return
false as needed in this case.

My question why interop change return code from false to true ?

TIA

Arkady
Mattias Sjögren - 09 Jan 2007 21:37 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Arkady Frenkel - 10 Jan 2007 07:09 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.