The test I did (I used ATL to host the control like I do it in C++) =>
(Add COM Reference : C:\Windows\System32\MsTscAx.dll)
Imports System.Runtime.InteropServices
Imports MSTSCLib
Public Class Form1
Public Enum HRESULT As Integer
S_OK = 0
S_FALSE = 1
E_NOINTERFACE = &H80004002
E_NOTIMPL = &H80004001
E_FAIL = &H80004005
E_UNEXPECTED = &H8000FFFF
E_OUTOFMEMORY = &H8007000E
End Enum
<DllImport("Atl.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function AtlAxWinInit() As Boolean
End Function
<DllImport("Atl.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function AtlAxGetControl(ByVal h As IntPtr, <Out> <MarshalAs(UnmanagedType.IUnknown)> ByRef pp As Object) As Integer
End Function
<DllImport("Atl.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function AtlAxGetHost(ByVal h As IntPtr, <Out> <MarshalAs(UnmanagedType.IUnknown)> ByRef pp As Object) As Integer
End Function
<DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function CreateWindowEx(ByVal dwExStyle As Integer, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hWndParent As IntPtr, ByVal hMenu As IntPtr, ByVal hInstance As IntPtr, ByVal lpParam As IntPtr) As IntPtr
End Function
Public Const WS_OVERLAPPED = &H0
Public Const WS_BORDER = &H800000
Public Const WS_POPUP = &H80000000
Public Const WS_CHILD = &H40000000
Public Const WS_MINIMIZE = &H20000000
Public Const WS_VISIBLE = &H10000000
Public Const WS_DISABLED = &H8000000
Public Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Integer) As Integer
If IntPtr.Size = 4 Then
Return GetWindowLong32(hWnd, nIndex)
End If
Return GetWindowLongPtr64(hWnd, nIndex)
End Function
<DllImport("User32.dll", EntryPoint:="GetWindowLong", CharSet:=CharSet.Auto)>
Private Shared Function GetWindowLong32(hWnd As IntPtr, nIndex As Integer) As Integer
End Function
<DllImport("User32.dll", EntryPoint:="GetWindowLongPtr", CharSet:=CharSet.Auto)>
Private Shared Function GetWindowLongPtr64(hWnd As IntPtr, nIndex As Integer) As Integer
End Function
Public Const GWL_HINSTANCE = -6
Private hWndContainer As IntPtr = IntPtr.Zero
Dim pMsTscNonScriptable As IMsTscNonScriptable = Nothing
Dim pMsRdpClient2 As IMsRdpClient2 = Nothing
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If (AtlAxWinInit()) Then
' CLSID_MsTscAxNotSafeForScripting
hWndContainer = CreateWindowEx(0, "AtlAxWin", "{A41A4187-5A86-4E26-B40A-856F9035D9CB}", WS_VISIBLE Or WS_CHILD Or WS_BORDER, 10, 10, 1180, 780, Handle, CType(10, IntPtr), CType(GetWindowLong(Me.Handle, GWL_HINSTANCE), IntPtr), IntPtr.Zero)
End If
Dim pUnknown As Object = Nothing
Dim hr As HRESULT = AtlAxGetControl(hWndContainer, pUnknown)
If (hr = HRESULT.S_OK) Then
pMsTscNonScriptable = CType(pUnknown, IMsTscNonScriptable)
pMsRdpClient2 = CType(pUnknown, IMsRdpClient2)
If (pMsRdpClient2 IsNot Nothing And pMsTscNonScriptable IsNot Nothing) Then
' Test with Demo Server
' https://www.secure-od.com/demo-server/
pMsTscNonScriptable.ClearTextPassword = "D3m02014*Test"
pMsRdpClient2.UserName = "demo2"
pMsRdpClient2.Server = "109.168.97.222"
pMsRdpClient2.DesktopWidth = 1920
pMsRdpClient2.DesktopHeight = 1080
pMsRdpClient2.Connect()
End If
End If
Me.ClientSize = New System.Drawing.Size(1200, 800)
CenterToScreen()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If (pMsRdpClient2 IsNot Nothing) Then
pMsRdpClient2.Disconnect()
End If
End Sub
End Class