static void Main(string[] args)
        {
            TraceListener[] listeners = new TraceListener[] { new TextWriterTraceListener(Console.Out) };
            Debug.Listeners.AddRange(listeners);


            IVMwareHorizonClient4 _client = (IVMwareHorizonClient4) new VMwareHorizonClient();

            IVMwareHorizonClientEvents5 ce = (IVMwareHorizonClientEvents5) new ClientEvents5();


            writeColor("This utility demo's how to hook the horizon client and beginning to listen to events.", ConsoleColor.Green, Console.ForegroundColor);

            _client.Advise2(ce, VmwHorizonClientAdviseFlags.VmwHorizonClientAdvise_None);
            Console.Title = "Press any key to disconnect from events.";


            var currentColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Debug.Write("Would you like to open a client now? [y/n]: ");
            Console.ForegroundColor = currentColor;
            var answer = Console.ReadLine();

            if (answer.ToLower() == "y")
            {
                System.Diagnostics.Process.Start("vmware-view://");
            }



            Console.ReadLine();
            _client.Unadvise();
            writeColor("No longer listening for events.", ConsoleColor.Green, Console.ForegroundColor);
            ce      = null;
            _client = null;
        }
        static void Main(string[] args)
        {
            //TraceListener[] listeners = new TraceListener[] { new TextWriterTraceListener(Console.Out) };
            //Debug.Listeners.AddRange(listeners);


            IVMwareHorizonClient4 _client = (IVMwareHorizonClient4) new VMwareHorizonClient();

            IVMwareHorizonClientEvents5 ce = new ClientEvents5();


            WriteColor("This utility demo's how to logon and launch a horizon resource programatically.", ConsoleColor.Green, true);


            _client.Advise2(ce, VmwHorizonClientAdviseFlags.VmwHorizonClientAdvise_None);

            var       server   = GetValidInput("Enter connection server name: ");
            var       username = GetValidInput("Enter Username: "******"Enter Password: "******"Enter Domain: ");
            LoginInfo li       = new LoginInfo
            {
                domainName                   = domain,
                password                     = password,
                username                     = username,
                loginAsCurrentUser           = 0,
                samlArtifact                 = "",
                smartCardPIN                 = "224466",
                unauthenticatedAccessAccount = "",
                unauthenticatedAccessEnabled = 0
            };

            bool validChoice = false;

            _client.ConnectToServer(server, li, VmwHorizonClientLaunchFlags.VmwHorizonClientLaunch_NonInteractive);
            while (!hasFailed)
            {
                if (hasLaunched)
                {
                    hasFailed = false;
                    WriteColor("Session created successfully: " + LaunchID, ConsoleColor.Green, true);
                    break;
                }

                if (hasAuthenticated)
                {
                    if (hasLaunchItems)
                    {
                        var i = 0;
                        foreach (var item in Launchitems)
                        {
                            Console.WriteLine("{0} - " + item.name, i);
                            i += 1;
                        }


                        while (!validChoice)
                        {
                            WriteColor("enter a number of a resource to launch: ", ConsoleColor.Cyan, false);
                            var choice = GetValidInput("");
                            try
                            {
                                int parseresult = 0;
                                if (int.TryParse(choice, out parseresult))
                                {
                                    if (parseresult >= 0 && parseresult <= i)
                                    {
                                        validChoice = true;
                                        var launchitem = Launchitems[parseresult];
                                        _client.ConnectToLaunchItem2(Serverid, launchitem.id, VmwHorizonClientProtocol.VmwHorizonClientProtocol_Default, VmwHorizonClientDisplayType.VmwHorizonClientDisplayType_WindowSmall, "");
                                    }
                                }
                                else
                                {
                                    validChoice = false;
                                }
                            }
                            catch (Exception ex)
                            {
                                validChoice = false;
                            }
                        }
                    }
                }
                System.Threading.Thread.Sleep(5000);
            }

            if (!hasFailed)
            {
                WriteColor("Press any key to log off the session", ConsoleColor.Cyan, false);
                Console.ReadLine();
                _client.LogoffProtocolSession(Serverid, launchtoken);
            }

            _client.ShutdownClient(Serverid, 1);
            _client.Unadvise();
            ce      = null;
            _client = null;
        }