none
Launch TS Remote App from Terminal Services API

    Pertanyaan

  • Hi,

    I'm using rdp files from "TS remote App manager" to launch remote apps without the anoying remote desktop. Now I found "Terminal Services API" and I'm able to launch remote applicatioms using the code below. Where can I set "remoteapplicationmode = 1" so my remote TS App runs without showing remote desktop?

    I tried using MsRdpClientShell.RdpFileContents = <rdp file contents> but in that case I'm unable to set and use virtual channels.

    Regards,
    Manuel Alves

    public Form1()
    {

    m_msTsc = new AxMsRdpClient6();

    m_msTsc.OnConnected += new EventHandler(m_msTsc_OnConnected);

    m_msTsc.OnDisconnected += new IMsTscAxEvents_OnDisconnectedEventHandler(m_msTsc_OnDisconnected);

    m_msTsc.OnChannelReceivedData += new IMsTscAxEvents_OnChannelReceivedDataEventHandler(m_msTsc_OnDataReceived);

    m_msTsc.Dock = DockStyle.Fill;

    Controls.Add(m_msTsc);

    InitializeComponent();

    }
    ...

    m_msTsc.Server = "myServer";

    m_msTsc.UserName = "myUser";

    m_msTsc.SecuredSettings2.StartProgram = "c:\\VirtualChannels\\VirtualChannelsServerApp.exe";

    m_msTsc.SecuredSettings2.AudioRedirectionMode = 2;

    m_msTsc.AdvancedSettings7.MaximizeShell = 0;

    m_msTsc.AdvancedSettings7.SmartSizing = true;

    m_msTsc.AdvancedSettings7.PublicMode = false;

    m_msTsc.AdvancedSettings7.AuthenticationLevel = 0;

    m_msTsc.AdvancedSettings7.ClearTextPassword = "myPassword";

    m_msTsc.AdvancedSettings7.DisableRdpdr = 0;

    m_msTsc.CreateVirtualChannels("CH001,CH002");

    m_msTsc.Connect();

    // Where can I set "remoteapplicationmode = 1"

    // so my remote TS App runs without showing remote desktop?

    Rabu, 25 Maret 2009 17.22

Jawaban

  • Hello,
     The RemoteProgramMode is a property of ITSRemoteProgram. You can try something along the following lines:


    axMsRdpClient6NotSafeForScripting1.RemoteProgram.RemoteProgramMode = true;

     

    Once you receive the OnConnectedEvent

    axMsRdpClient6NotSafeForScripting1.RemoteProgram.ServerStartProgram(<program to start...>);

    Please note that the ServerStartProgram must be invoked only after OnConnected is received.

    Hope this helps.

    Selasa, 07 April 2009 19.56
    Moderator

Semua Balasan

  • Sorry but I am not able to understand your question. Are you saying that after using "remoteapplicationmode = 1" , you are no longer able to use virtual channels?

    Thanks!
    Jumat, 27 Maret 2009 22.50
  • No, I just can't find where to set remoteapplicationmode. If I populate AxMsRdpClient6 properties to launch a remote session I always get a remote desktop when I invoke Connect(). I would like to run the remote app without the remote desktop.

    By looking at the .rdp file produced by Windows 2008 “TS Remote App Manager” it looks like the only difference is the "remoteapplicationmode" property. Unfortunately I’m unable to find this on the AxMsRdpClient6 object.

    My dilemma:

    If I use an .rdp file generated by “TS Remote App Manager” I don’t know how to set up channels but I get a nice remote app running without remote desktop, behaving like if it was a local window

    If I set the properties of the AxMsRdpClient6 (see my fist post) I can set up channels but now I also see my remote app running inside a remote desktop.

    Is it possible to get both worlds (a remote app running without remote desktop and using channels)?

    Thanks for your time,

    Manuel Alves

     

    Sabtu, 28 Maret 2009 23.14
  • Hello,
     The RemoteProgramMode is a property of ITSRemoteProgram. You can try something along the following lines:


    axMsRdpClient6NotSafeForScripting1.RemoteProgram.RemoteProgramMode = true;

     

    Once you receive the OnConnectedEvent

    axMsRdpClient6NotSafeForScripting1.RemoteProgram.ServerStartProgram(<program to start...>);

    Please note that the ServerStartProgram must be invoked only after OnConnected is received.

    Hope this helps.

    Selasa, 07 April 2009 19.56
    Moderator
  • Hi,
    Thanks for your reply. Unfortunately setting RemoteProgram.RemoteProgramMode always returns an error like "error trying to reference a non existing token" (rough translation to English). Same error if one tries to call RemoteProgram.ServerStartProgram(...

    Looks like nobody knows how to use ITSRemoteProgram:
    http://social.technet.microsoft.com/Forums/en-US/winserverTS/thread/2820135c-fe81-4715-af3e-ce6fb78c01d1

    http://msdn.microsoft.com/en-us/library/aa382952(VS.85).aspx


    Best regards,
    Manuel Alves.
    Rabu, 08 April 2009 12.05
  • Hi debaprajna,

    Thanks for your advice. It solved my problem. I was getting the error (previous post) because I was instantiating AxMsRdpClient6 instead of AxMsRdpClient6NotSafeForScripting.

    Best regards,
    manuel Alves
    Rabu, 08 April 2009 16.39
  • Hello Alves,

    We are running against the same type of problems, could you post (or email (R.Lemstra_at_xso.nl ) a full working sample ?

    Thanks in advance.

    regards,

    Rinse


    Senin, 06 Juli 2009 11.17
  • Did anyone get a code example?  I tryied putting the axMsRdpClient7NotSafeForScripting1.RemoteProgram.ServerStartProgram(<program to start...>); in the OnConnected event handler, but no luck.  I am using the MsRdpWebAccessLib activeX for now.

    thanks
    -John
    Selasa, 21 Juli 2009 06.21
  • Hi Manuel - please use the Icon "Insert Code Block" - which is the right most Icon.
    Citrix Technology Professional, PubForum.net Founder, LinkedIn, TS Training in Europe! Love Microsoft &its people to bits!
    Selasa, 21 Juli 2009 09.41
    Moderator
  • Thanks Dr. Conti for the tip but until I swith compatibility view from explorer 8 to 7 I could not open this editor window...


    Hi Grant,
    This are several code fragments I'm using. Just paste it on a form code window and clean the extra variables I'm using.

    To generate the DLLs for this object use "Aximp c:\Windows\system32\mstscax.dll".
    It generates assemblies Mstsclib.dll and Axmstsclib.dll for the RDP client ActiveX control Mstscax.dll
    Add a reference to these DLLs in your TS client project

    Before any coding test the published application using the rdp file created by terminal services remote app. Make sure the server app (the remote app) is working as expected.

    The code snipets:

    ' 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

     

      

     

    Selasa, 21 Juli 2009 09.58
  • Manual,

    Thanks for the code example.  I got it working.  However I noticed when I use mstscax.dll the remote desktop session appears to be part of my applications process space.  If I use MsRdpWebAccess.dll i can create the remote app session independent of my applications process space.

    Selasa, 21 Juli 2009 21.20
  • Hello,

    I have created an RDP-control based on this article:
    http://www.codeproject.com/KB/cs/Rem...CSharpNET.aspx

    I added reference to "Microsoft Terminal Services Control Type Library” from the COM tab.
    This added MSTSCLib.dll and AxMSTSCLib to the project. These two are interops of some COM native component.

    How can I verify on which win OS my exe will work on?
    meaning how can I know which Windows system contains/support these two COM components?
    Is there any easy way to check ?
    Kamis, 03 Juni 2010 05.05
  •  RClient.Connect() works fine. 

    But if we disconnect the connection and try to connect again using this process

    we got error 

    if axMsRdpClient6NotSafeForScripting1.RemoteProgram.RemoteProgramMode = true

     Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

       at MSTSCLib.IMsRdpClient6.Connect()

    We have to close form and again load it and then have to connect again. then only connection works again.

    is there any other way to connect if we have disconnected.

    Sabtu, 14 Juli 2018 06.12