From: junlia on
Hi Everyone,

I have implemented sending message via virtual channel to terminal service
server app in C#. However, due to the project requirement, I need to re-write
this in VB6. And I am having issues with MsRdpClient31.CreateVirtualChannels
and MsRdpClient31.SendOnVirtualChannel methods. I received Method
'CreateVirtualChannels' of object 'MsRdpClient31' failed and
Method 'SendOnVirtualChannel' of object 'MsRdpClient31' failed errors.

If I put in 'On Error Resume Next' statement before the the methods calls,
it would skip the first SendOnVirtualChannel call as it would error out, and
does the subsequent SendOnVirtualChannel without any error. One odd thing is
that I can not send the same message immediately after the failed
SendOnVirtualChannel call. Sample code attached below.

Any pointers would be appreciated.

Thanks
Junlia

PS. attched is the sample code:

Private Sub Command1_Click()

On Error Resume Next
Set Rdp = MsRdpClient31.Object
MsRdpClient31.Server = Text1.Text
MsRdpClient31.UserName = "user"
MsRdpClient31.DesktopHeight = 600
MsRdpClient31.DesktopWidth = 800
Rdp.ClearTextPassword = "password"
MsRdpClient31.SecuredSettings.WorkDir = "C:\test\"
MsRdpClient31.SecuredSettings.StartProgram = "C:\test\tsserverconsole.exe"

If Err.Number <> 0 Then
MsgBox "befor create VC: err " & Err.Number & "; desc: " & Err.Description
Err.Clear
End If
MsRdpClient31.CreateVirtualChannels ("TSCS")
If Err.Number <> 0 Then
MsgBox "create VC: err " & Err.Number & "; desc: " & Err.Description
Err.Clear
End If

MsRdpClient31.Connect
' wait fro connection to establish
Dim i As Integer
For i = 0 To 20000
i = i + 1
Next i

If Err.Number <> 0 Then
MsgBox "Before send: err " & Err.Number & "; desc: " & Err.Description
Err.Clear
End If

MsRdpClient31.SendOnVirtualChannel "TSCS", "SUZUKI"

If Err.Number <> 0 Then
MsgBox "send suzuki err " & Err.Number & "; desc: " & Err.Description
Err.Clear
End If

'---- if uncomment the next line, the code from here on will not get
executed. ----
'MsRdpClient31.SendOnVirtualChannel "TSCS", "SUZUKI"
MsRdpClient31.SendOnVirtualChannel "TSCS", "FORD"
If Err.Number <> 0 Then
MsgBox "send Ford err " & Err.Number & "; desc: " & Err.Description

Err.Clear
End If


MsRdpClient31.SendOnVirtualChannel "TSCS", "SUZUKI"
If Err.Number <> 0 Then
MsgBox "send suzuki err " & Err.Number & "; desc: " & Err.Description
Err.Clear
End If
End Sub


From: Larry Serflaten on

"junlia" <junlia(a)discussions.microsoft.com> wrote

>
> MsRdpClient31.Connect
> ' wait fro connection to establish
> Dim i As Integer
> For i = 0 To 20000
> i = i + 1
> Next i

This isn't a good way to wait for anything. You basically tie up the CPU
in a do-nothing loop. If you're waiting for something to happen, don't
hog the CPU.

You did not show MsRdpClient31 defined anywhere, so I can't go look
it up very easily, but if it has a Connect method, shouldn't it also have a
Connected property to indicate a successful connection has been
extablished? (Or some similarly named property....)

It would be better to wait for that type of property to indicate the
connection than to force the CPU into a do-nothing loop

Something like (air code)

Dim wait as Date
wait = DateAdd("s", 3, now)
Do
DoEvents
Loop Until (Now > Wait) Or MsRdpClient31.Connected

If Not MsRdpClient31.Connected Then
Msgbox "Connection failed (took longer than 3 seconds)."
Exit Sub
end If

Waiting 3 seconds will be the same on all machines. Looping from
0 to 10000 (effectively) can vary from machine to machine depending
on CPU speed. Look for a 'ConnectionEstablished' property, however
they want to call it, and then try the code above. If nothing else, change
the loop to wait for a certain amount of time, rather than the do-nothing
loop....

Dim wait as Date
wait = DateAdd("s", 3, now)
Do
DoEvents
Loop Until (Now > Wait)

HTH
LFS



From: junlia on
Larry, Thanks much for pointing that out, and I am with you. This is just
sample code I put there for illustration purpose only. In the real code, I
wait server app to send message back before sending message from client.

Any pointers to the errors with msrdp APIs would be appreciated.

Thanks,
Junlia

"Larry Serflaten" wrote:

>
> "junlia" <junlia(a)discussions.microsoft.com> wrote
>
> >
> > MsRdpClient31.Connect
> > ‘ wait fro connection to establish
> > Dim i As Integer
> > For i = 0 To 20000
> > i = i + 1
> > Next i
>
> This isn't a good way to wait for anything. You basically tie up the CPU
> in a do-nothing loop. If you're waiting for something to happen, don't
> hog the CPU.
>
> You did not show MsRdpClient31 defined anywhere, so I can't go look
> it up very easily, but if it has a Connect method, shouldn't it also have a
> Connected property to indicate a successful connection has been
> extablished? (Or some similarly named property....)
>
> It would be better to wait for that type of property to indicate the
> connection than to force the CPU into a do-nothing loop
>
> Something like (air code)
>
> Dim wait as Date
> wait = DateAdd("s", 3, now)
> Do
> DoEvents
> Loop Until (Now > Wait) Or MsRdpClient31.Connected
>
> If Not MsRdpClient31.Connected Then
> Msgbox "Connection failed (took longer than 3 seconds)."
> Exit Sub
> end If
>
> Waiting 3 seconds will be the same on all machines. Looping from
> 0 to 10000 (effectively) can vary from machine to machine depending
> on CPU speed. Look for a 'ConnectionEstablished' property, however
> they want to call it, and then try the code above. If nothing else, change
> the loop to wait for a certain amount of time, rather than the do-nothing
> loop....
>
> Dim wait as Date
> wait = DateAdd("s", 3, now)
> Do
> DoEvents
> Loop Until (Now > Wait)
>
> HTH
> LFS
>
>
>
>
From: junlia on

Thanks much for your help, Larry.

MsRdpClient31 is an object within msrdp.ocx -- Microsoft's terminal service
client connection control. You can download it from
http://www.microsoft.com/windowsxp/downloads/tools/rdclientdl.mspx, install
and extract it, then register msrdp.ocx.

The only other code you might need is: Private Rdp As IMsTscNonScriptable
'at class level

Thanks,
Junlia


"Larry Serflaten" wrote:

>
> "junlia" <junlia(a)discussions.microsoft.com> wrote
>
> >
> > MsRdpClient31.Connect
> > ‘ wait fro connection to establish
> > Dim i As Integer
> > For i = 0 To 20000
> > i = i + 1
> > Next i
>
> This isn't a good way to wait for anything. You basically tie up the CPU
> in a do-nothing loop. If you're waiting for something to happen, don't
> hog the CPU.
>
> You did not show MsRdpClient31 defined anywhere, so I can't go look
> it up very easily, but if it has a Connect method, shouldn't it also have a
> Connected property to indicate a successful connection has been
> extablished? (Or some similarly named property....)
>
> It would be better to wait for that type of property to indicate the
> connection than to force the CPU into a do-nothing loop
>
> Something like (air code)
>
> Dim wait as Date
> wait = DateAdd("s", 3, now)
> Do
> DoEvents
> Loop Until (Now > Wait) Or MsRdpClient31.Connected
>
> If Not MsRdpClient31.Connected Then
> Msgbox "Connection failed (took longer than 3 seconds)."
> Exit Sub
> end If
>
> Waiting 3 seconds will be the same on all machines. Looping from
> 0 to 10000 (effectively) can vary from machine to machine depending
> on CPU speed. Look for a 'ConnectionEstablished' property, however
> they want to call it, and then try the code above. If nothing else, change
> the loop to wait for a certain amount of time, rather than the do-nothing
> loop....
>
> Dim wait as Date
> wait = DateAdd("s", 3, now)
> Do
> DoEvents
> Loop Until (Now > Wait)
>
> HTH
> LFS
>
>
>
>
From: junlia on
More details of the problem:

I did install different versions of rdp web connection controls on my
machine, but only registered one msrdp.ocx. Even after I un-install the RDP
web connection software, the program still run with the same problems as
stated above. Not sure if I am getting into the dll hell situation... I run
the app at a win 2000 machine, still got the errors at these methods calls,
but with different error message " Automation error".

Any pointers would be appreciated.

Thanks,
Junlia

"junlia" wrote:

> Hi Everyone,
>
> I have implemented sending message via virtual channel to terminal service
> server app in C#. However, due to the project requirement, I need to re-write
> this in VB6. And I am having issues with MsRdpClient31.CreateVirtualChannels
> and MsRdpClient31.SendOnVirtualChannel methods. I received Method
> 'CreateVirtualChannels' of object 'MsRdpClient31' failed and
> Method 'SendOnVirtualChannel' of object 'MsRdpClient31' failed errors.
>
> If I put in 'On Error Resume Next' statement before the the methods calls,
> it would skip the first SendOnVirtualChannel call as it would error out, and
> does the subsequent SendOnVirtualChannel without any error. One odd thing is
> that I can not send the same message immediately after the failed
> SendOnVirtualChannel call. Sample code attached below.
>
> Any pointers would be appreciated.
>
> Thanks
> Junlia
>
> PS. attched is the sample code:
>
> Private Sub Command1_Click()
>
> On Error Resume Next
> Set Rdp = MsRdpClient31.Object
> MsRdpClient31.Server = Text1.Text
> MsRdpClient31.UserName = "user"
> MsRdpClient31.DesktopHeight = 600
> MsRdpClient31.DesktopWidth = 800
> Rdp.ClearTextPassword = "password"
> MsRdpClient31.SecuredSettings.WorkDir = "C:\test\"
> MsRdpClient31.SecuredSettings.StartProgram = "C:\test\tsserverconsole.exe"
>
> If Err.Number <> 0 Then
> MsgBox "befor create VC: err " & Err.Number & "; desc: " & Err.Description
> Err.Clear
> End If
> MsRdpClient31.CreateVirtualChannels ("TSCS")
> If Err.Number <> 0 Then
> MsgBox "create VC: err " & Err.Number & "; desc: " & Err.Description
> Err.Clear
> End If
>
> MsRdpClient31.Connect
> ' wait fro connection to establish
> Dim i As Integer
> For i = 0 To 20000
> i = i + 1
> Next i
>
> If Err.Number <> 0 Then
> MsgBox "Before send: err " & Err.Number & "; desc: " & Err.Description
> Err.Clear
> End If
>
> MsRdpClient31.SendOnVirtualChannel "TSCS", "SUZUKI"
>
> If Err.Number <> 0 Then
> MsgBox "send suzuki err " & Err.Number & "; desc: " & Err.Description
> Err.Clear
> End If
>
> '---- if uncomment the next line, the code from here on will not get
> executed. ----
> 'MsRdpClient31.SendOnVirtualChannel "TSCS", "SUZUKI"
> MsRdpClient31.SendOnVirtualChannel "TSCS", "FORD"
> If Err.Number <> 0 Then
> MsgBox "send Ford err " & Err.Number & "; desc: " & Err.Description
>
> Err.Clear
> End If
>
>
> MsRdpClient31.SendOnVirtualChannel "TSCS", "SUZUKI"
> If Err.Number <> 0 Then
> MsgBox "send suzuki err " & Err.Number & "; desc: " & Err.Description
> Err.Clear
> End If
> End Sub
>
>