Click here to Skip to main content
13,256,123 members (40,770 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
 Global object reference.
Public m_msTsc As AxMSTSCLib.AxMsRdpClient6NotSafeForScripting = Nothing
 
 
 
Private Sub startSession()
       _Connected = False ' Global var
 
        m_msTsc = New AxMSTSCLib.AxMsRdpClient6NotSafeForScripting
 
        With m_msTsc
 
            .Dock = DockStyle.Fill
 
            AddHandler .OnConnected, AddressOf m_msTsc_OnConnected
 
            AddHandler .OnDisconnected, AddressOf m_msTsc_OnDisconnected
 
            AddHandler .OnChannelReceivedData, AddressOf m_msTsc_OnDataReceived
 
            AddHandler .OnFatalError, AddressOf m_msTsc_OnFatalError
 
            AddHandler .OnLogonError, AddressOf m_msTsc_OnLogonError
 
            AddHandler .OnWarning, AddressOf m_msTsc_OnWarning
 
        End With
 
        Me.Controls.Add(m_msTsc)
 
 
 
        With Me
 
            .Opacity = 0
 
            .Visible = False
 
            .WindowState = FormWindowState.Minimized
 
            .ShowInTaskbar = False
 
            .FormBorderStyle = Windows.Forms.FormBorderStyle.None
 
            .Width = Screen.PrimaryScreen.WorkingArea.Width
 
            .Height = Screen.PrimaryScreen.WorkingArea.Height
 
        End With
 
        TimerConnect.Enabled = True
 
 
 
    End Sub
 
 
 
Private Sub TimerConnect_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerConnect.Tick
 
 
 
        Try
 
 
 
            TimerConnect.Enabled = False
 
            FormPleaseWait.Close()
 
            FormPleaseWait.Show()
 
            Application.DoEvents()
 
 
 
            Dim rdpPort As Integer = 3389
 
            Dim remoteServer As String
 
            If gibUser.isInternal Then
 
                remoteServer = gibUser.serverInternal
 
            Else
 
                remoteServer = gibUser.server
 
            End If
 
 
 
            If remoteServer.Contains(":") Then
 
                Dim p() As String = remoteServer.Split(":")
 
                remoteServer = p(0)
 
                rdpPort = CInt(p(1))
 
            End If
 
 
 
            With m_msTsc
 
 
 
                .Server = remoteServer
 
                .UserName = gibUser.userName
 
                If Not gibUser.userName.Contains("\") Then
 
                    .Domain = gibUser.domain
 
                End If
 
                .RemoteProgram.RemoteProgramMode = True
 
                .AdvancedSettings7.RDPPort = rdpPort
 
                .AdvancedSettings7.PublicMode = False ' Para usar as credenciais que lhes passamos aqui
 
                .AdvancedSettings7.AuthenticationLevel = 0
 
                .AdvancedSettings7.ClearTextPassword = gibUser.Password
 
                .AdvancedSettings7.EnableAutoReconnect = True
 
                .AdvancedSettings7.DisableRdpdr = 0
 
                .AdvancedSettings7.RedirectClipboard = True
 
                .AdvancedSettings7.RedirectPrinters = True
 
                .AdvancedSettings7.RedirectDevices = False
 
                .AdvancedSettings7.RedirectDrives = False
 
                .AdvancedSettings7.RedirectPorts = False
 
                .AdvancedSettings7.RedirectPOSDevices = False
 
                .AdvancedSettings7.RedirectSmartCards = False
 
                .AdvancedSettings7.SmartSizing = False 'http: 'msdn.microsoft.com/en-us/library/aa381256(VS.85).aspx
 
                .ColorDepth = My.Settings.ColorDepth 'int value can be 8, 15, 16, 24 or 32
 
                .SecuredSettings2.AudioRedirectionMode = 2 ' 0 redirect 1 play on server 2 disable
 
                .CreateVirtualChannels("CHANEL001,CHANEL002,CHANEL003,CHANEL004")
 
                .Connect()
 
                TimerConnectTimeout.Enabled = True
 
 
 
            End With
 
 
 
        Catch ex As Exception
 
            MsgBox(ex.Message, MsgBoxStyle.Critical)
 
            Me.Close()
 
        End Try
 
 
 
    End Sub
 
 
 
    Private Sub m_msTsc_OnConnected(ByVal sender As Object, ByVal e As EventArgs)
 
 
 
        FormPleaseWait.Label1.Text = "Launching remote app..."
 
        _Connected = True
 
        launchRemoteApp()
 
        RDP_SESSION = True
 
 
 
    End Sub
 
 
 
    Public Sub launchRemoteApp()
 
        Dim workingDir As String = gibUser.remoteAppPath
 
        workingDir = workingDir.Substring(0, workingDir.LastIndexOf("\"))
 
        m_msTsc.RemoteProgram.ServerStartProgram(gibUser.remoteAppPath, "", workingDir, False, "", False)
 
        _mainForm.credentialsDelete()
 
    End Sub
 
 
 
 
 
Private Sub m_msTsc_OnDataReceived(ByVal sender As Object, ByVal e As AxMSTSCLib.IMsTscAxEvents_OnChannelReceivedDataEvent)
 
 
 
        Dim data As String = cleanCString(e.data.ToString)
 
        Dim channel = e.chanName.ToString
 
 
 
        MsgBox("Virtual Channel " + e.chanName.ToString() + vbCrLf + data)
 
    End Sub
 
    Private Function cleanCString(ByVal cString As String) As String
 
        Dim s As New System.Text.StringBuilder
 
        For i As Integer = 0 To cString.Length
 
            If Asc(cString.Substring(i, 1)) = 0 Then
 
                Exit For
 
            End If
 
            s.Append(cString.Substring(i, 1))
 
        Next
 
        Return s.ToString
 
    End Function


What I have tried:

tried to execute in vb.net but can't do ....
Posted 14-Nov-17 8:56am
Updated 14-Nov-17 9:33am
Comments
CHill60 14-Nov-17 14:57pm
   
A suggestion for any future questions you might post ... don't say "can't do", explain what happens or what error messages you receive. We can't see your screen, examine your HDD nor read your mind.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Quote:
Can anybody help me to execute this code step by step because I am beginer to the vb.net

The tool you are looking is the debugger.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
Visual Basic / Visual Studio Video Tutorial - Basic Debugging - YouTube[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 14 Nov 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100