public static void _SA_StartProgram(bool bUseSample, string CompanyPath)
        {
            // or hard wait?
            while (!SelectCompany.repo.SelfInfo.Exists(Variables.iExistWaitTime))
            {
                Thread.Sleep(1000);
            }

            if (!SelectCompany.repo.Self.Visible)
            {
                _SA_StartSage50();

//                // handle the PU download dialog
//                if (DownloadUpdate.Instance.Window.Exists())
//                {
//                    DownloadUpdate.Instance.Window.SetActive();
//                    DownloadUpdate.Instance.DownloadLater.Click();
//                }

                // check if restart message shows
                // SimplyMessage._SA_HandleMessage(SimplyMessage.repo.No);
            }

            // we have to check this when the product is not yet registered
            // the below window only shows when company is already registered, therefore we need it to skip everything with registration window shows
            while (!SelectCompany.repo.Self.Visible)
            {
                Thread.Sleep(1000);
            }

            SelectCompany.repo.Self.Activate();

            if (Functions.GoodData(CompanyPath))
            {
                SelectCompany.repo.SelectAnExistingCompany.Click();
                SelectCompany.repo.OK.Click();

                OpenCompany.repo.Self.Activate();
                Simply._SA_OpenCompany(CompanyPath);
            }
            else
            {
                if (bUseSample)
                {
                    SelectCompany.repo.OpenSampleCompany.Click();
                }
                else    // defaults to last company opened
                {
                    // A Recently used company radio button and Last company you worked on are the same
                    if (SelectCompany.repo.OpenARecentlyUsedCompanyInfo.Exists())
                    {
                        SelectCompany.repo.OpenARecentlyUsedCompany.Click();
                    }
                    else        // log error
                    {
                        Functions.Verify(false, true, "The radio list item to open the last company used is found");
                    }
                }
                SelectCompany.repo.Self.Activate();
                SelectCompany.repo.OK.Click();

                // If necessary wait for CM service to start
                // Handle CM error, in main machine CM service is not started when opening sample db
                while (!SimplyMessage.repo.CmMessageTextInfo.Exists())
                {
                    if (UpgradeCompany.repo.SelfInfo.Exists() || SimplyMessage.repo.SelfInfo.Exists())
                    {
                        break;
                    }
                }

                if (SimplyMessage.repo.CmMessageTextInfo.Exists())                      // Ranorex see select company as SimplyMessage as well
                {
                    if (SimplyMessage.repo.CmMessageText.TextValue.Contains(SimplyMessage.sCmNotRunningMsg) || SimplyMessage.repo.CmMessageText.TextValue.Contains(SimplyMessage.sCmNotFoundMsg))
                    {
                        try
                        {
                            iCmTry++;
                            // Maximum 7 tries
                            if (iCmTry > 8)
                            {
                                Functions.Verify(false, true, "CM service started");
                            }
                            else
                            {
                                // wait
                                System.Threading.Thread.Sleep(10000);
                                SimplyMessage.repo.Self.Activate();
                                // SimplyMessage.repo.TryAgain.Click();
                                SimplyMessage.repo.Close.Click();                                       // if tryagain doesn't work
                                // Try from select company dialog again
                                _SA_StartProgram(bUseSample, CompanyPath);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
                else
                {
                    // for beta
                    // SimplyMessage.Instance._SA_HandleMessage(SimplyMessage.OK_LOC);

                    // handle messages and stuff to get to home window
                    Simply._SA_GotoHomeWindow();

                    // get the build number
                    //binfo.sBuildNumber =GetSimplyBuildNumber( + Simply.Instance._SA_GetProgramPath () + "simplyaccounting.exe"); NC

                    // set flavor
                    Simply._SA_SetFlavorVariables();

                    // get version Cdn or US
                    // Simply._SA_getVersion (true);
                }
            }
        }