We help IT Professionals succeed at work.

VB App that tries to use Sendkey to login to a Citrix client

cbrown-aps asked
Last Modified: 2012-06-22
I am trying to launch a Citrix client and send keystrokes to log in automatically from a VB app. The problem is until my app hits a breakpoint or finishes executing the Citrix client will not finish loading and display the login screen. I can insert a breakpoint and the login screen will display. Then I let my app run and it will login to the client just like I want it to. I need my app to give up control so that the login can finish loading. Then it needs to start up and send the keystrokes.

Here is the code as a console app. I've tried it without the threading and also in a windows app.

Imports system.Diagnostics
Imports System.ComponentModel
Imports System.Threading
Module Module1
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindow As String) As Integer
    Public Declare Function ShowWindow Lib "user32" Alias "ShowWindowA" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Integer) As Integer
    Sub Main()
        Dim StartTime As Date = DateTime.Now
        Dim CitrixStartThread As New Thread(AddressOf CitrixStart)
        Dim CitrixLoginThread As New Thread(AddressOf CitrixLogin)

        CitrixStartThread.Name = "CitrixStartThread"

            If StartTime.AddSeconds(25) <= DateTime.Now Then
                Exit Do
            End If

        CitrixLoginThread.Name = "CitrixLoginThread"
    End Sub

    Private Sub CitrixStart()
        Dim proc As New Process
        proc.StartInfo.FileName = "net6vpn.exe"
        proc.StartInfo.WorkingDirectory = "c:\program files\net6"
    End Sub

    Private Sub CitrixLogin()
        Dim hWnd As Integer = FindWindow(Nothing, "Citrix Secure Access")
        If hWnd <= 0 Then
            'MessageBox.Show("Application Not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If
        Dim i As Integer = 1
        For i = 1 To 10
            My.Computer.Keyboard.SendKeys("$mcdermott$~", True)
    End Sub
End Module
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)

Is suppose to work, but I haven't had much luck with it.

I think it only works once the application is started, and you have a window handle to it.

Were you able to sendkey strokes to citrix app from a VB app without much headaches?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.