VB.net从Active Directory获取bitlocker密码ID

时间:2017-05-16 20:38:59

标签: vb.net active-directory bitlocker

我有一个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)

1 个答案:

答案 0 :(得分:0)

所以我发现我需要将字节转换为十六进制,以使它们与Microsoft管理控制台中查看的内容相匹配。一旦我开始这样做,我遇到的唯一问题是我发现字节数组的索引与Active Directory中的索引顺序不同。 - 所以不是循环,而是我必须列出Byte数组的每个索引,并将它们排序到正确的位置,以便它们与它们在AD中的显示方式相匹配。

我的最终功能是:

Function bitread(ByVal GUID As Byte())
    Dim tempVar As String
    tempVar = GUID(3).ToString("X02") & GUID(2).ToString("X02") _
        & GUID(1).ToString("X02") & GUID(0).ToString("X02") & "-" _
        & GUID(5).ToString("X02") & GUID(4).ToString("X02") & "-" _
        & GUID(7).ToString("X02") & GUID(6).ToString("X02") & "-" _
        & GUID(8).ToString("X02") & GUID(9).ToString("X02") & "-" _
        & GUID(10).ToString("X02") & GUID(11).ToString("X02") _
        & GUID(12).ToString("X02") & GUID(13).ToString("X02") _
        & GUID(14).ToString("X02") & GUID(15).ToString("X02")
    Return tempVar
End Function

跟:

bitread(Item.Properties("msFVE-RecoveryGUID")(0))