|
| DSOBJECTNAMES Structure in C# 2.0 |
 |
Wed, 14 Nov 2007 12:05:48 -080 |
I need to access the DSOBJECTNAMES Structure in a C# 2.0 property
extension page.
According to this page: http://msdn2.microsoft.com/en-us/library/ms676011.aspx
it's declared in header Dsclient.h. I guess this is C stuff. Can
anyone tell me where to find this so I can use it in my .NET program?
|
| Post Reply
|
| Re: DSOBJECTNAMES Structure in C# 2.0 |
 |
Thu, 15 Nov 2007 06:10:33 -080 |
With help from others, I've worked round this. This isn't the
finished code but it will get you the ADsPath of the item selected to
use with a System.DirectoryServices.DirectoryEntry object.
This is the code from the sample, modified to use my new methods:
public void RefreshData(SharedDataItem sharedDataItem)
{
this.MachineName.Text = GetUser(sharedDataItem);
machinePropertyPage.Dirty = false;
}
Then you just need to add these methods. This will enable you to see
the ADsPath of the selected user (or whatever):
private string GetUser(SharedDataItem sharedDataItem)
{
if (sharedDataItem == null)
{
return "null";
}
byte[] dsObjectNames = sharedDataItem.GetData();
uint itemCount = GetDWORD(dsObjectNames, 16);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < (int)itemCount; i++)
{
int offsetLocationForADsPath = 28 + i * 16;
int offsetLocationForSchemaClass = 32 + i * 16;
uint offsetForADsPath = GetDWORD(dsObjectNames,
offsetLocationForADsPath);
uint offsetForSchemaClass = GetDWORD(dsObjectNames,
offsetLocationForSchemaClass);
string aDsPath = GetString(dsObjectNames,
offsetForADsPath);
string schemaClass = GetString(dsObjectNames,
offsetForSchemaClass);
if (schemaClass.ToLower() != "user")
continue;
sb.AppendLine(aDsPath);
}
return sb.ToString();
}
I've used the for loop because you can select multiple objects and I
haven't worked out how not to display the page if multiple users are
selected.
private static uint GetDWORD(byte[] userNames, int index)
{
MemoryStream ms = new MemoryStream(userNames, index, 4);
BinaryReader br = new BinaryReader(ms);
return br.ReadUInt32();
}
private static string GetString(byte[] dsObjectNames, uint
offset)
{
//Data is in unicode format so characters are stored
//as a pair of bytes with the least sig byte first.
//Each string is terminated by null which is two zero
//bytes, i.e. 00 00.
List<Byte> stringBytes = new List<byte>();
bool previousByteNotNull = true;
//int offset = (int)dsObjectNames[offsetLocation];
byte tempByte = dsObjectNames[offset];
while (previousByteNotNull || tempByte != byte.MinValue)
{
stringBytes.Add(tempByte);
if (tempByte == byte.MinValue)
previousByteNotNull = false;
else
previousByteNotNull = true;
offset++;
tempByte = dsObjectNames[offset];
}
byte[] byteArray = stringBytes.ToArray();
return Encoding.Unicode.GetString(byteArray);
}
ssg31415926 wrote:
> I need to access the DSOBJECTNAMES Structure in a C# 2.0 property
> extension page.
>
> According to this page:
http://msdn2.microsoft.com/en-us/library/ms676011.aspx
> it's declared in header Dsclient.h. I guess this is C stuff. Can
|
| Post Reply
|
| Re: DSOBJECTNAMES Structure in C# 2.0 |
 |
Thu, 15 Nov 2007 16:29:34 -080 |
Have a look at my post here (http://groups.google.com/group/
microsoft.public.management.mmc/browse_thread/thread/98727e6e96e9d08d)
for an example on how to resolve the problem with multiple selected
objects. It also shows another example on how to handle DSOBJECTNAMES.
Regards
|
| Post Reply
|
|
|
|
|
|
|
|
|
|