10. 大きい整数の属性と対象のオブジェクト
属性
表示
U ser
G roup
C om puter
OU
Pri
nter
V ol e
um
accountExpi
res
日付
○
○
badPassw ordT i e
m
日付
○
○
l
astC ontentIndexed
日付
l
astLogoff
日付
○
○
l
astLogon
日付
○
○
l
astLogonT i estam p
m
日付
○
○
l
ockoutT i e
m
日付/整数
○
○
m axS torage
整数
○
○
m sD S -C ached-M em bershi i e-S tam p
p-T m
日付
○
○
m sD S -LastFai edInteracti
l
veLogonT i e
m
日付
○
○
m sD S -LastS uccessful
Interacti
veLogonT i e
m
日付
○
○
m sD S -U serPassw ordExpi i eC om puted
ryT m
日付
○
○
pw dLastS et
日付
○
○
uS N C hanged
整数
○
○
○
○
○
○
uS N C reated
整数
○
○
○
○
○
○
uS N D S A LastO bjR em oved
整数
○
○
○
○
○
○
uS N LastO bjR em
整数
○
○
○
○
○
○
uS N S ource
整数
○
○
○
○
○
○
○
10
12. 大きい整数取得1 呼出し側の抜粋(VB)
Public Shared Sub OutputProperties(
entry As DirectoryEntry, filePath As String)
Dim props = entry.Properties.PropertyNames.Cast(
Of String)().OrderBy(Function(s) s).ToList()
'プロパティ名のリス
ト
For Each pname In props
'プロパティ数分
Dim val = entry.Properties.Item(pname).Value
If TypeOf val Is Byte() Then
'バイト配列の時
'バイト値を取得
ElseIf TypeOf val Is IADsLargeInteger Then
'大きい整数の時
Dim li = GetLargeIntegerValue(
pname, DirectCast(val, IADsLargeInteger)) '大きい整数値を取得
Else
'それ以外の時
'各値を取得
End If
Next
End Sub
12
13. 大きい整数取得1 呼出し側の抜粋(C#)
public static void OutputProperties(
DirectoryEntry entry, string filePath) {
var props = entry.Properties.PropertyNames.
Cast<string>().OrderBy(s => s).ToList();
//プロパティ名のリスト
foreach (var pname in props) {
//プロパティ数分
var val = entry.Properties[pname].Value;
if (val is byte[]) {
//バイト配列の時
//バイト値を取得
} else if (val is IADsLargeInteger) {
//大きい整数の時
var li = GetLargeIntegerValue(
pname, (IADsLargeInteger)val);
//大きい整数値を取得
} else {
//それ以外の時
//各値を取得
}
}
}
13
14. 大きい整数取得2 呼出し側の抜粋(VB)
Public Shared Sub OutputOptionalProperties(
entry As DirectoryEntry, filePath As String)
Dim schema = DirectCast(
entry.SchemaEntry.NativeObject, IADsClass) 'スキーマ オブジェクト
Dim props = DirectCast(
schema.OptionalProperties, Object()) 'オプションのプロパティ
'プロパティをディレクトリ ストアから読込
entry.Invoke("GetInfoEx", props, 0)
For Each pname As String In props
'オプションのプロパティ数分
Dim pvcol = entry.Properties.Item(pname) 'PropertyValueCollection
If pvcol.Value Is Nothing Then '値がない時
Continue For
End If
14
15. 大きい整数取得2 呼出し側の抜粋(VB)
If TypeOf pvcol.Value Is Byte() Then
'バイト配列の時
'バイト値を取得
ElseIf TypeOf pvcol.Value Is IADsLargeInteger Then '大きい整数の時
Dim li = GetLargeIntegerValue(pname,
DirectCast(pvcol.Value, IADsLargeInteger)) '大きい整数値を取得
Else
'それ以外の時
'各値を取得
End If
Next
End Sub
15
16. 大きい整数取得2 呼出し側の抜粋(C#)
public static void OutputOptionalProperties(
DirectoryEntry entry, string filePath) {
//スキーマ オブジェクト
var schema = (IADsClass)entry.SchemaEntry.NativeObject;
//オプションのプロパティ
var props = (object[])schema.OptionalProperties;
//プロパティをディレクトリ ストアから読込
entry.Invoke("GetInfoEx", props, 0);
foreach (string pname in props) {
//オプションのプロパティ数分
var pvcol = entry.Properties[pname]; //PropertyValueCollection
if (pvcol.Value == null) {
//値がない時
continue;
}
16
17. 大きい整数取得2 呼出し側の抜粋(C#)
if (pvcol.Value is byte[]) {
//バイト配列の時
//バイト値を取得
} else if (val is IADsLargeInteger) {
//大きい整数の時
var li = GetLargeIntegerValue(
pname, (IADsLargeInteger)pvcol.Value);
//大きい整数値を取得
} else {
//それ以外の時
//各値を取得
}
}
}
17
18. 大きい整数値の取得(VB)
Private Shared Function GetLargeIntegerValue(
name As String, value As IADsLargeInteger) As Object
Dim lval = Convert.ToInt64(value.HighPart.ToString("x8") &
value.LowPart.ToString("x8"), 16)
If name.Equals("lockoutTime") Then 'ロックアウトしたことがある時
If lval > 0 Then 'ロックアウト中又はロックアウト期間が過ぎただけの
時
Return String.Format("{0}({1})",
lval, DateTime.FromFileTime(lval)) '判り易いよう日付も付ける
End If
Return lval
End If
If IsInteger(name, lval) Then '整数の時
Return New Guid(value).ToString()
End If
18
19. 大きい整数値の取得(VB)
If (lval = 0) OrElse (lval = Int64.MaxValue) Then
Return "(なし)"
End If
Return DateTime.FromFileTime(lval)
'#1/1/1601#.AddTicks(lval).ToLocalTime() と同じ
End Function
19
22. 整数かどうかの確認(VB)
Private Shared Function IsInteger(
name As String, value As Long) As Boolean
If name.Equals("maxStorage") Then
Return True
End If
If name.StartsWith("msDs-") Then
Return False
End If
If name.StartsWith("uSN") Then
Return True
End If
Return False
End Function
22
23. 整数かどうかの確認(C#)
private static bool IsInteger(string name, long value) {
if (name.Equals("maxStorage")) {
return true;
}
if (name.StartsWith("msDs-")) {
return false;
}
if (name.StartsWith("uSN")) {
return true;
}
return false;
}
23