Back to the basic apps I started with.
There were a couple of locations where the output was "System.Byte[]" or "System.Object[]".
System.Object[] appears to happen in "msifilelist", and only on those apps that have a transform.
Given that you're loading everything into a DataRow, code like this will separate out the transform if one exists:
foreach (object a in myDirectoryEntry.Properties["msifilelist"])
{
if (a.ToString().ToLower().EndsWith(".mst"))
dr["Transforms"] = a.ToString();
else
dr["msifilelist"] += a.ToString();
}
The System.Byte[] is a bit more complex.
In a similar way,
foreach (object a in myDirectoryEntry.Properties["productcode"])
works to get the bytes out of the ProductCode property, but the object contains an array. You can't access the contents of an array from within an object -- a[1] isn't valid, and none of the casts I tried worked.
Found some code online to convert an object to an array of bytes. It works, to an extent, but there's quite a bit of extra stuff tacked on to both the beginning and the end of the array. I don't know why - it's got to come from something in that function, but I can't tell where.
Simple enough to loop through and clean it up:
StringBuilder sb = StringBuilder();
byte[] code = ObjectToByteArray(a);
int i = 0;
foreach (byte b in code)
{
if (i++ >= 27)
{
sb.Append(b.ToString("X2"));
}
}
string outString = ToString();
However, the GUID as returned from AD doesn't match what it should. Not only is this just an array of bytes, but the dashes are missing and the bytes in the first three sections are in a jumbled order.
One would have thought that
Guid g = new Guid(outstring);
outString = g.ToString("B");
would have taken care of that -- and it does add in the dashes, but the byte order is still off.. and by off, I mean like this:
If the proper GUID is {12345678-ABCD-1234-ABCD-123456789AB}, the returned GUID is {78563412-CDAB-3412-ABCD-123456789AB}. I know this is a side effect of how Windows handles GUIDs internally, and there's probably an easy way to fix it, but I couldn't find it. So, I did my own:
StringBuilder newString = new StringBuilder();
newString.Append("{");
newString.Append(outString.Substring(6, 2));
newString.Append(outString.Substring(4, 2));
newString.Append(outString.Substring(2, 2));
newString.Append(outString.Substring(0, 2));
newString.Append("-");
newString.Append(outString.Substring(10, 2));
newString.Append(outString.Substring(8, 2));
newString.Append("-");
newString.Append(outString.Substring(14, 2));
newString.Append(outString.Substring(12, 2));
newString.Append("-");
newString.Append(outString.Substring(16, 4));
newString.Append("-");
newString.Append(outString.Substring(20, 12));
newString.Append("}");
return newString.ToString().ToUpper();
So, there you have it. Nothing groundbreaking, but if you're just trying to get the product or upgrade codes from AD, here's the missing piece from the code I already put up. I would have expected the Package Code to be in AD as well, but it's not.
Print | posted on Monday, October 01, 2007 8:33 AM