or:
[StructLayoutAttribute(Lay
class SID_IDENTIFIER_AUTHORITY {
[MarshalAs(UnmanagedType.B
public byte[] Value;
}
Main Topics
Browse All TopicsHi Experts,
does anybody know how to use LsaAddAccountRights in C# ?
This is my declaration:
[System.Runtime.InteropSer
private static extern long LsaAddAccountRights(
IntPtr PolicyHandle,
IntPtr AccountSid,
LSA_UNICODE_STRING UserRights,
long CountOfRights );
The function requires a SID buffer, so I also have to declare AllocateAndInitializeSid and LookupAccountName...
private static extern bool AllocateAndInitializeSid(
SID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
int nSubAuthorityCount,
long dwSubAuthority0, long dwSubAuthority1,
long dwSubAuthority2, long dwSubAuthority3,
long dwSubAuthority4, long dwSubAuthority5,
long dwSubAuthority6, long dwSubAuthority7,
out IntPtr pSid );
[System.Runtime.InteropSer
private static extern bool LookupAccountName(
String lpSystemName,
String lpAccountName,
IntPtr Sid,
ref int cbSid,
String DomainName,
ref int cbDomainNameSize,
IntPtr peUse);
...and SID_IDENTIFIER_AUTHORITY:
[StructLayoutAttribute(Lay
class SID_IDENTIFIER_AUTHORITY {
[MarshalAsAttribute(Unmana
public byte[] Value;
}
At runtime AllocateAndInitializeSid throws an exception:
"System.Runtime.InteropSer
The type Definition contains no layout informationen."
So I have changed the StructLayot-Attribute:
[StructLayoutAttribute(Lay
class SID_IDENTIFIER_AUTHORITY {
[MarshalAsAttribute(Unmana
public byte[] Value;
}
With that declaration AllocateAndInitializeSid throws a different exception:
"System.TypeLoadException:
This type cannot be marshalled as a structure field."
What's wrong with my declaration?
I can't find a readable example, so every hint would be very great!
greets,
coco
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The second one seems to work, now AllocateAndInitializeSid causes a NullReferenceException.
I've tried this one:
SID_IDENTIFIER_AUTHORITY auth = new SID_IDENTIFIER_AUTHORITY()
auth.Value = new byte[6]{0,0,0,0,0,5};
AllocateAndInitializeSid(a
An this one:
AllocateAndInitializeSid(n
Both calls throw a NullReferenceException (or something .NET interprets like that).
If I start the application as a service, GetLastError returns ERROR_FILE_NOT_FOUND. When the I put the same code into a windows application, it returns ERROR_MOD_NOT_FOUND.
Hello again,
now I've tried ConvertStringSidToSid:
[System.Runtime.InteropSer
private static extern bool ConvertStringSidToSid(
String StringSid,
IntPtr Sid
);
...
ConvertStringSidToSid("S-1
Console.WriteLine(GetLastE
The Errorcode is ERROR_INVALID_HANDLE.
What-in-the-world am I doing wrong?
Business Accounts
Answer for Membership
by: Nebulus_Posted on 2003-07-11 at 06:26:08ID: 8902254
maybe this will work:
outKind.Se quential)]
[StructLayoutAttribute(Lay
class SID_IDENTIFIER_AUTHORITY {
public byte Value0;
public byte Value1;
public byte Value2;
public byte Value3;
public byte Value4;
public byte Value5;
}