VB.NET TSUSEREXLib.dll在Windows 10下不起作用

时间:2017-01-06 07:11:15

标签: .net windows-10 terminal-services

我使用DLL" Interop.TSUSEREXLib.dll"确定AD帐户的终端服务配置文件路径。 到目前为止,这对Win7作为我的客户没有任何问题。 相同的代码不适用于Windows 10。

这是一个简短的代码示例:

var newData = [
  {value1: "a", value2: 1},
  {value1: "b", value2: 2},
  {value1: "c", value2: 3}
]

使用Win10始终显示上面的MessageBox。

有没有人知道如何确定使用Windows 10作为客户端的ActiveDirectory用户的TS属性?

我使用Win10 x64和VS2015 Express。 谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用此处说明的解决方案:https://blog.cjwdev.co.uk/2014/08/24/vb-net-decode-ad-userparameters-attribute-values/

Public Function GetUserParamsValue(UserParametersText As String, PropertyName As String, IsInteger As Boolean) As String
    Dim Bytes() As Byte = System.Text.Encoding.Unicode.GetBytes(UserParametersText)
    Dim Start As Integer = UserParametersText.IndexOf(PropertyName)
    Dim StartingByteCount As Integer = ((Start + PropertyName.Length) * 2)
    Dim ValueLength As UInt16 = Convert.ToUInt16(Bytes((Start * 2) - 4))
    Dim Counter As Integer = 0

    If IsInteger Then
        Dim HexBytes((CInt(ValueLength / 2) - 1)) As Byte
        For i As Integer = StartingByteCount To CInt(StartingByteCount + (ValueLength - 1)) Step +2
            Dim OriginalCharHex As String = Chr(Bytes(i)) & Chr(Bytes(i + 1))
            HexBytes(Counter) = CByte(Integer.Parse(OriginalCharHex))
            Counter += 1
        Next
        Return BitConverter.ToUInt32(HexBytes, 0).ToString
    Else
        Dim HexBytes(CInt(ValueLength / 2) - 2) As Byte
        For i As Integer = StartingByteCount To CInt(StartingByteCount + (ValueLength - 3)) Step +2
            Dim OriginalCharHex As String = Chr(Bytes(i)) & Chr(Bytes(i + 1))
            Dim CharHexDecimal As Integer = Convert.ToInt32(OriginalCharHex, 16)
            HexBytes(Counter) = CByte(CharHexDecimal)
            Counter += 1
        Next
        Return System.Text.Encoding.ASCII.GetString(HexBytes)
    End If
End Function

在这个网站上有一个完整的代码来编码和解码userParameters,包括一些解释:https://00laboratories.com/resources/code/c-sharp/microsoft-active-directory-userparameters-header

相关问题