"Jan Nielsen" <ja*******@onli ne.nospam> wrote in message
news:uI******** ******@tk2msftn gp13.phx.gbl...
In a C# application I'm using the NetShareGetInfo API function to get some
information about a share.
This is working all right.
Now I want my application to be able to display the contents of the
security descriptor as well.
Using NetShareGetInfo I get a IntPtr (SECURITY_DESCR IPTOR*) to the
security descriptor. I would like to convert this into an
ActiveDs.IADsSe curityDescripto r.
I've tried the following:
ActiveDs.IADsSe curityDescripto r sd =
(ActiveDs.IADsS ecurityDescript or)securityUtil ity.ConvertSecu rityDescriptor( pSd1,
2, 1);
but it throws an exception 0x8000500C.
Can this be done at all ? And if so, how ???
It seems like it possible to get the SD by using
IADsSecurityUti lity::GetSecuri tyDescriptor. However as I allready have the
data from NetShareGetInfo , I would just like to convert it into a format
easier to work with.
Thanks in advace,
Jan Nielsen
Jan,
You can't pass a raw pointer as argument to ConvertSecurity Descriptor, this
method takes a VARIANT of type byte array (VT_I1|VT_ARRAY ).
So you have to marshal the SD to a byte[] with correct length.
To get the lenght of the SD call GetSecurityDesc riptorLength, here's the
signature:
[DllImport("adva pi32", SetLastError=tr ue)]
internal static extern uint GetSecurityDesc riptorLength(In tPtr byteArray);
uint sdLength = GetSecurityDesc riptorLength(pS d1);
Now create an array with the length returned using Marshal.Copy and call
your method like this:
byte[] sdArray = new byte[sdLength];
Marshal.Copy(pS d1, buffer1, 0, (int) sdLength);
ADsSecurityUtil ityClass asu = new ADsSecurityUtil ityClass();
IADsSecurityDes criptor sdi =
(IADsSecurityDe scriptor)asu.Co nvertSecurityDe scriptor(sdArra y,2, 1);
As you see, you need another PInvoke call, and that's bad, there's no need
to call NetShareGetInfo , you better stick to System.Director yServices to get
the SD from a remote share.
Willy.