VB.NET TSUSEREXLib.dll does not work under windows 10

512 views Asked by At

I use the DLL "Interop.TSUSEREXLib.dll" to determine the terminalservices profilepath for an AD-Account. This worked so far without problems with Win7 as my client. The same code does not work with Windows 10.

Here is a short code example:

Imports TSUSEREXLib

Dim oTsUser As IADsTSUserEx = Nothing
oTsUser = TryCast(New DirectoryEntry(ADsPath).NativeObject, IADsTSUserEx)

If oTsUser Is Nothing Then
   MessageBox.Show("Die Terminalservices-Attribute konnten nicht ermittelt werden!")
   Return Nothing
End If

Dim sReturnValue As String = Nothing

sReturnValue = oTsUser.TerminalServicesProfilePath

Using Win10 the above MessageBox is always displayed.

Does anyone know a way to determine the TS attributes of an ActiveDirectory user with Windows 10 as client?

I use Win10 x64 with VS2015 Express. Thank you!

1

There are 1 answers

2
Kel On

You can use the solution explained here: 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

And on this site there is a complete code to encode and decode the userParameters including some explanation: https://00laboratories.com/resources/code/c-sharp/microsoft-active-directory-userparameters-header