我有一个 VB.net 程序,我正在尝试添加一个 bitlocker 查找工具,该工具将在活动目录中搜索机器名称,并显示“密码 ID”以及“恢复密码”
到目前为止,我的脚本/代码完美地用于查找和显示恢复密码,但我无法让它显示密码 ID。
我试过了:
Item.Properties("msFVE-RecoveryGuid")(0)
返回错误“System.InvalidCastException:从类型 'Byte()' 到类型 'String' 的转换无效。”
Item.Properties("msFVE-RecoveryGuid")(0).ToString
返回“System.Byte []”
Item.Properties("msFVE-RecoveryGuid").ToString
返回“System.DirectoryServices.ResultPropertyValueCollection”
到目前为止,在我的搜索中,我只看到了 C# 示例,并且无法翻译。
但是,恢复密码也是如此:
(Item.Properties("msFVE-RecoveryPassword")(0))
这是我对上下文的较大片段:
Dim RootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADsearch As New DirectorySearcher("LDAP://" & DomainDN)
ADsearch.Filter = ("(&(objectClass=computer)(name=" & MachineName & "))")
Dim ADresult As SearchResult = ADsearch.FindOne
Dim ADpath As String = ADresult.Path
Dim BTsearch As New DirectorySearcher()
BTsearch.SearchRoot = New DirectoryEntry(ADpath)
BTsearch.Filter = "(&(objectClass=msFVE-RecoveryInformation))"
Dim BitLockers As SearchResultCollection = BTsearch.FindAll()
Dim Item As SearchResult
Dim longTempstring As String = ""
For Each Item In BitLockers
If Item.Properties.Contains("msFVE-RecoveryGuid") Then
Dim tempstring As String = Item.Properties("msFVE-RecoveryGuid")(0).ToString
longTempstring = longTempstring & tempstring & vbNewLine
'ListBox2.Items.Add(Item.Properties("msFVE-RecoveryGuid")(0))
End If
If Item.Properties.Contains("msFVE-RecoveryPassword") Then
ListBox1.Items.Add(Item.Properties("msFVE-RecoveryPassword")(0))
End If
Next
MsgBox(longTempstring)