question

stefanofattori avatar image
0 Votes"
stefanofattori asked stefanofattori action

Create RDP application on VB.NET

Hello, is there a new way to create RDP application with .NET 5.0? I tried COM RDP components v12 and MS Terminal Service 1 and they don't work on visual studio 2019. I tried WTSQuerySessionInformation classes and they don't work. What can I use for this project? Thank you so much Stefano

dotnet-standard
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tested with MSTSCLib (MsTscAx.dll) and it worked :
(by creating the window dynamically, then getting IMsRdpClient2)

72197-rdp.jpg


0 Votes 0 ·
rdp.jpg (119.2 KiB)
Castorix31 avatar image
0 Votes"
Castorix31 answered

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



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

stefanofattori avatar image
0 Votes"
stefanofattori answered stefanofattori commented

How did you import dll in vb project?
Are the controls rdp on toolbox section disabled?

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Just with "Add COM Reference"
Controls could not been added in the Toolbox, but it is not a big problem as they can be created by code instead of with the Designer

0 Votes 0 ·

Ok thanks, but I can't find any tutorial to use that dll classes..

0 Votes 0 ·

The documentation is in MSDN (Remote Desktop ActiveX controll


0 Votes 0 ·
Show more comments
stefanofattori avatar image
0 Votes"
stefanofattori answered

Please, can I also ask you how did you add rdp control to the form? I can't find right class of it...
My code:

 Dim frmTemp As New Form
    
 Dim rdpView As New MSTSCLib.MsTscAxNotSafeForScripting
    
 rdpView.Server = "ip server"
 rdpView.UserName = "user"
    
 frmTemp.Controls.Add(rdpView)
 frmTemp.Show()
 rdpView.Connect()

But it doesn't work, I'm not sure that MSTSCLib.MsTscAxNotSafeForScripting is the right control to use.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

stefanofattori avatar image
0 Votes"
stefanofattori answered stefanofattori commented

A lot of code... :)

I found other example like this 354007-vbnet-terminal-server-application



using this code:

 Dim rdpconnection As New AxMsRdpClient9NotSafeForScripting
            Dim newTabPage As New DevExpress.XtraTab.XtraTabPage
            newTabPage.Text = txtserver.Text
            XtraTabControl1.TabPages.Add(newTabPage)
            newTabPage.Controls.Add(rdpconnection)
    
            rdpconnection.Dock = DockStyle.Fill
            rdpconnection.UserName = txtusername.Text
            rdpconnection.Domain = "AKD"
            rdpconnection.Server = txtserver.Text
    
            Dim secured As MSTSCLib.IMsTscNonScriptable = DirectCast(rdpconnection.GetOcx(), MSTSCLib.IMsTscNonScriptable)
            secured.ClearTextPassword = txtpassword.Text
    
            rdpconnection.Connect()

but I can't understand what is "AxMsRdpClient9NotSafeForScripting", I can't find it in MSTSCLib.

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Most of the code I posted are declarations
The code itself doing the connection is not big...
AxMsRdpClient9NotSafeForScripting is the ActiveX control, that you can get in . NET Framework, but you said you use .NET 5

0 Votes 0 ·

Yes, and is there any control like that in NET 5?
also does it support shadow connection?

0 Votes 0 ·

In the code, I used the MsTscAxNotSafeForScripting ActiveX to display it inside a Form
It is just not present in the Toolbox (I tested in .NET Framework and controls are correctly added in the Toolbox)
I did not find a shadow flag in interfaces...

0 Votes 0 ·
Show more comments
stefanofattori avatar image
0 Votes"
stefanofattori answered stefanofattori edited

Hi everybody,
I found a way to connect to windows 10 using this property:

 RdpClient.AdvancedSettings9.EnableCredSspSupport = True

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.