static void Main(string[] args)
        {
            ICAClientClass ica = new ICAClientClass();
            onLogonResetEvent = new AutoResetEvent(false);

            // Launch published Notepad if you comment this line, and uncommented
            // the one above you will launch a desktop session
            ica.Application = "#Standard Desktop";
            // ica.InitialProgram = "#Notepad";

            // Launch a new session
            ica.Launch = true;

            // Set Server address
            ica.Address = "172.16.11.40";

            // No Password property is exposed (for security)
            // but can explicitly specify it by using the ICA File "password" property
            ica.Username = "******";
            ica.Domain = "cherryhealth";
            ica.SetProp("Password", "Password78");

            // Let's have a "pretty" session
            ica.DesiredColor = ICAColorDepth.Color24Bit;

            // Reseach the output mode you want, depending on what your trying
            // to attempt to automate. The "Client Simulation APIs" are only available under certain modes
            // (i.e. things like sending keys to the session, enumerating windows, etc.)
            ica.OutputMode = OutputMode.OutputModeNormal;

            // Height and Width
            ica.DesiredHRes = 1024;
            ica.DesiredVRes = 786;

            // Register for the OnLogon event
            ica.OnLogon += new _IICAClientEvents_OnLogonEventHandler(ica_OnLogon);

            // Launch/Connect to the session
            ica.Connect();

            if (onLogonResetEvent.WaitOne(new TimeSpan(0, 2, 0)))
                Console.WriteLine("Session Logged on sucessfully! And OnLogon Event was Fired!");
            else
                Console.WriteLine("OnLogon event was NOT Fired! Logging off ...");

            // Do we have access to the client simulation APIs?
            if (ica.Session == null)
                Console.WriteLine("ICA.Session object is NULL! :(");

            Console.WriteLine("\nPress any key to log off");
            Console.Read();

            // Logoff our session
            Console.WriteLine("Logging off Session");
            ica.Logoff();
        }
        static void Main(string[] args)
        {
            string serverIP = "";
            string domain = "";
            string username = "";
            string password = "";
            int wait = 15;

            if (args.Length != 5)
            {
                Console.WriteLine("Usage: XenAppTestLogin <Server IP> <Domain> <Username> <Password> <Wait Time> \n");
                Environment.Exit(2);
            }
            else
            {
                serverIP = args[0];
                domain = args[1];
                username = args[2];
                password = args[3];
                wait = Convert.ToInt32(args[4]);

            }

            //Console.WriteLine("after if");

            ICAClientClass ica = new ICAClientClass();
            onLogonResetEvent = new AutoResetEvent(false);

            // launch a desktop session
            ica.Application = "";

            // Launch a new session
            ica.Launch = true;

            //Console.WriteLine("after session launch");

            // Set Server address
            //ica.Address = "10.8.X.X";
            ica.Address = serverIP;

            // Not Password field exposed (for security)
            // but can specify it by using the ICA File "password" property
            /*ica.Username = "******";
            ica.Domain = "xxxx";
            ica.SetProp("Password", "xxxx");
             */
            ica.Username = username;
            ica.Domain = domain;
            ica.SetProp("Password", password);

            // Let's have a "pretty" session
            //ica.DesiredColor = ICAColorDepth.Color24Bit;

            // Reseach the output mode you want, depending on what your trying
            // to attempt to automate. The "Client Simulation APIs" are only available under certain modes
            // (i.e. things like sending keys to the session, enumerating windows, etc.)
            ica.OutputMode = OutputMode.OutputModeWindowless;
            // ica.OutputMode = OutputMode.OutputModeNormal;

            // Height and Width
            //ica.DesiredHRes = 1024;
            //ica.DesiredVRes = 786;

            //Console.WriteLine("before onlogon");

            // Register for the OnLogon event
            ica.OnLogon += new _IICAClientEvents_OnLogonEventHandler(ica_OnLogon);

            // Launch/Connect to the session
            ica.Connect();

            //Console.WriteLine("after connect");

            if (onLogonResetEvent.WaitOne(new TimeSpan(0, 0, wait)))
            {
                Console.WriteLine("ConnectionEstablished True");
                //Environment.Exit(0);
            }
            else
            {
                Console.WriteLine("ConnectionEstablished False");
                //Environment.Exit(2);
            }

            // Logoff our session
            ica.Logoff();
            //Console.WriteLine("after logoff");
        }
        static void Main(string[] args)
        {
            ICAClientClass ica = new ICAClientClass();

            onLogonResetEvent = new AutoResetEvent(false);

            // Launch published Notepad if you comment this line, and uncommented
            // the one above you will launch a desktop session
            ica.Application = "#Standard Desktop";
            // ica.InitialProgram = "#Notepad";

            // Launch a new session
            ica.Launch = true;

            // Set Server address
            ica.Address = "172.16.11.40";

            // No Password property is exposed (for security)
            // but can explicitly specify it by using the ICA File "password" property
            ica.Username = "******";
            ica.Domain   = "cherryhealth";
            ica.SetProp("Password", "Password78");

            // Let's have a "pretty" session
            ica.DesiredColor = ICAColorDepth.Color24Bit;

            // Reseach the output mode you want, depending on what your trying
            // to attempt to automate. The "Client Simulation APIs" are only available under certain modes
            // (i.e. things like sending keys to the session, enumerating windows, etc.)
            ica.OutputMode = OutputMode.OutputModeNormal;

            // Height and Width
            ica.DesiredHRes = 1024;
            ica.DesiredVRes = 786;

            // Register for the OnLogon event
            ica.OnLogon += new _IICAClientEvents_OnLogonEventHandler(ica_OnLogon);

            // Launch/Connect to the session
            ica.Connect();

            if (onLogonResetEvent.WaitOne(new TimeSpan(0, 2, 0)))
            {
                Console.WriteLine("Session Logged on sucessfully! And OnLogon Event was Fired!");
            }
            else
            {
                Console.WriteLine("OnLogon event was NOT Fired! Logging off ...");
            }

            // Do we have access to the client simulation APIs?
            if (ica.Session == null)
            {
                Console.WriteLine("ICA.Session object is NULL! :(");
            }

            Console.WriteLine("\nPress any key to log off");
            Console.Read();

            // Logoff our session
            Console.WriteLine("Logging off Session");
            ica.Logoff();
        }