Beispiel #1
0
        public CalculatorService()
        {
            wmiObj = new WMIObject();

            //publish the object to WMI in order to be viewed
            Instrumentation.Publish(wmiObj);
        }
Beispiel #2
0
 public SentenceInfo(string key, String sqlSentence)
 {
     this.sqlSentence = sqlSentence;
     this.name        = key;
     sentenceCount    = 0;
     Instrumentation.Publish(this);
 }
Beispiel #3
0
 private void PublishCache()
 {
     foreach (var v in _cache)
     {
         Instrumentation.Publish(v);
     }
 }
        private void ComputerHardwareAdded(IHardware hardware)
        {
            if (!Exists(hardware.Identifier.ToString()))
            {
                foreach (ISensor sensor in hardware.Sensors)
                {
                    HardwareSensorAdded(sensor);
                }

                hardware.SensorAdded   += HardwareSensorAdded;
                hardware.SensorRemoved += HardwareSensorRemoved;

                Hardware hw = new Hardware(hardware);
                _activeInstances.Add(hw);

                try
                {
                    Instrumentation.Publish(hw);
                }
                catch { }
            }

            foreach (IHardware subHardware in hardware.SubHardware)
            {
                ComputerHardwareAdded(subHardware);
            }
        }
Beispiel #5
0
 public WMIDataStoreProvider(string datastoreName) : base()
 {
     instanceProvidersBase = WMIDataStoreProviders.Instance();
     Name = datastoreName;
     instanceProvidersBase.AddDataStoreInfo(Name, false);
     Instrumentation.Publish(this);
 }
Beispiel #6
0
        private void HardwareSensorAdded(ISensor data)
        {
            Sensor sensor = new Sensor(data);

            activeInstances.Add(sensor);

            Instrumentation.Publish(sensor);
            Logger.LogInformation($"Registered Sensor {sensor.Name} in WMI provider");
        }
        /// <summary>
        /// publishes a message to the WMI repository
        /// </summary>
        /// <param name="MessageText">the message text</param>
        /// <param name="Type">the message type</param>
        public static MyWMIInterface Publish()
        {
            // create a new message
            MyWMIInterface pInterface = new MyWMIInterface();

            Instrumentation.Publish(pInterface);

            return(pInterface);
        }
        public static void Main(string[] args)
        {
            MyManagedElement el = new MyManagedElement();

            el.Description = "SAMPLE INSTANCE";
            el.Count       = 256;
            Instrumentation.Publish(el);
            Console.ReadLine();
            Instrumentation.Revoke(el);
        }
Beispiel #9
0
        private void HardwareSensorAdded(ISensor data)
        {
            Sensor sensor = new Sensor(data);

            activeInstances.Add(sensor);

            try {
                Instrumentation.Publish(sensor);
            } catch (Exception) { }
        }
Beispiel #10
0
    static void Mainz()
    {
//        Console.WriteLine(AppDomain.CurrentDomain.Pr
        int c;

        for (c = 0; c < 10000; c++)
        {
            Instrumentation.Publish(new inst());
        }
        Console.WriteLine("Check Instance");
        Console.ReadLine();
    }
        public static void Main(string[] args)
        {
            MyManagedElement el = new MyManagedElement();

            el.Description = "SAMPLE INSTANCE";
            el.Count       = 256;
            Instrumentation.Publish(el);
            Console.WriteLine("Instance published (true/false): {0}", el.Published);
            Console.ReadLine();
            Instrumentation.Revoke(el);
            Console.WriteLine("Instance published (true/false): {0}", el.Published);
        }
Beispiel #12
0
 public WMIDataSource(GxDataStore dataSource)
 {
     try
     {
         this.dataSource = dataSource;
         Instrumentation.Publish(this);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "WMI Error", e);
     }
 }
Beispiel #13
0
 public WMIConnection(GxConnection connection)
 {
     try
     {
         this.connection = connection;
         Instrumentation.Publish(this);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "WMI Error", e);
     }
 }
Beispiel #14
0
 public WMIServerUserInformation(int handle, ServerUserInformation userInfo)
 {
     try
     {
         this.userInfo = userInfo;
         this.handle   = handle;
         Instrumentation.Publish(this);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "WMI Error", e);
     }
 }
Beispiel #15
0
        private void HardwareSensorAdded(ISensor data)
        {
            String computerComponentId = data.Hardware.Identifier.ToString();
            String sensorId            = data.Identifier.ToString().Remove(0, computerComponentId.Length);

            DataManager.RegisterSensor(computerComponentId, sensorId, data.Name, (int)data.SensorType);

            Sensor sensor = new Sensor(data);

            activeInstances.Add(sensor);
            try {
                Instrumentation.Publish(sensor);
            } catch (Exception) { }
        }
Beispiel #16
0
 public void PublishInformer(WmiReadynessInformer obj)
 {
     if (ContainsInformer(obj))
     {
         throw new ArgumentException("This informer has already been already published.", "obj.ApplicationName = " + obj.ApplicationName);
     }
     if (obj.GetType().GetCustomAttributes(typeof(ManagementEntityAttribute), false).Any())
     {
         InstrumentationManager.Publish(obj);
     }
     else
     {
         Instrumentation.Publish(obj);
     }
     _inform.Add(obj.ApplicationName, obj);
 }
Beispiel #17
0
 /// <summary>
 /// Published object to WMI. Automatically recognizes .NET 2.0 and 3.5 classes (through reflection).
 /// Exceptions are thrown if the object has been already published or if the assembly is not installed.
 /// </summary>
 /// <param name="obj"></param>
 public void Publish(IWmiHardwareEntity obj)
 {
     if (Contains(obj))
     {
         throw new ArgumentException("This IHardware object is already published.", "obj.Hwid = " + obj.Hwid);
     }
     if (obj.GetType().GetCustomAttributes(typeof(ManagementEntityAttribute), false).Any())
     {
         InstrumentationManager.Publish(obj);
     }
     else
     {
         Instrumentation.Publish(obj);
     }
     _pub.Add(obj.Hwid, obj);
 }
Beispiel #18
0
 public WMICacheItem(string SQLStatement, ICacheItemExpiration expiration, object item)
 {
     try
     {
         this.stmt      = SQLStatement;
         this.cacheItem = item;
         timeCreated    = DateTime.Now;
         itemExpiration = expiration;
         keySize        = 10 + (2 * SQLStatement.Length);
         Instrumentation.Publish(this);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "WMI Error", e);
     }
 }
Beispiel #19
0
 public static WMIApplicationServer Instance()
 {
     lock (syncObj)
     {
         if (instance == null)
         {
             try
             {
                 instance = new WMIApplicationServer();
                 Instrumentation.Publish(instance);
             }
             catch (Exception e)
             {
                 GXLogging.Error(log, "WMI Error", e);
             }
         }
     }
     return(instance);
 }
Beispiel #20
0
 public WMICache(InProcessCache cache)
 {
     try
     {
         this.cache = cache;
         string size;
         if (Config.GetValueOf("CACHE_STORAGE_SIZE", out size) && Convert.ToInt32(size) > 0)
         {
             maxCacheStorageSize = Convert.ToInt64(size) * 1024;
         }
         else
         {
             maxCacheStorageSize = -1;
         }
         wmicacheItems = new Hashtable();
         Instrumentation.Publish(this);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "WMI Error", e);
     }
 }
Beispiel #21
0
        private void ComputerHardwareAdded(IHardware hardware)
        {
            if (!Exists(hardware.Identifier.ToString()))
            {
                foreach (ISensor sensor in hardware.Sensors)
                {
                    HardwareSensorAdded(sensor);
                }

                hardware.SensorAdded   += HardwareSensorAdded;
                hardware.SensorRemoved += HardwareSensorRemoved;

                Hardware hw = new Hardware(hardware);
                activeInstances.Add(hw);
                Instrumentation.Publish(hw);
                Logger.LogInformation($"Registered {hw.Name} in WMI provider");
            }

            foreach (IHardware subHardware in hardware.SubHardware)
            {
                ComputerHardwareAdded(subHardware);
            }
        }
Beispiel #22
0
    static void Maina()
    {
        Instrumentation.RegisterAssembly(typeof(Appo).Assembly);

        BadProp2 inst2 = new BadProp2();

        Instrumentation.Publish(inst2);
        Instrumentation.Publish(inst2);
        Instrumentation.Revoke(inst2);
        Instrumentation.Revoke(inst2);

        BadProp inst = new BadProp();

        Instrumentation.Publish(inst);
        Console.WriteLine(inst.Published);
        Instrumentation.Publish(inst);
        Console.WriteLine(inst.Published);

        Instrumentation.Revoke(inst);
        Console.WriteLine(inst.Published);

        inst.Published = true;
        Console.WriteLine(inst.Published);
    }
Beispiel #23
0
        private WMIDataStoreProviders()
        {
            Instrumentation.Publish(this);

            try
            {
                if (!PerformanceCounterCategory.Exists("GeneXusCounters"))
                {
                    CounterCreationDataCollection CounterDatas   = new CounterCreationDataCollection();
                    CounterCreationData           statementCount = new CounterCreationData();
                    statementCount.CounterName = "StatementCount";
                    statementCount.CounterHelp = "SQL Statement Count";
                    statementCount.CounterType = PerformanceCounterType.NumberOfItems64;
                    CounterDatas.Add(statementCount);
                    PerformanceCounterCategory.Create("GeneXusCounters", "GeneXus Counters", CounterDatas);
                }
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "WMI Performance countes error", e);
            }

            try{
                statementCounter          = new PerformanceCounter("GeneXusCounters", "StatementCount", "instance1", false);
                statementSelectCounter    = new PerformanceCounter("GeneXusCounters", "StatementCount", "instance1", false);
                statementUpdateCounter    = new PerformanceCounter("GeneXusCounters", "StatementUpdateCount", "instance1", false);
                statementDeleteCounter    = new PerformanceCounter("GeneXusCounters", "StatementDeleteCount", "instance1", false);
                statementInsertCounter    = new PerformanceCounter("GeneXusCounters", "StatementInsertCount", "instance1", false);
                statementCallCounter      = new PerformanceCounter("GeneXusCounters", "StatementCallCount", "instance1", false);
                statementDirectSQLCounter = new PerformanceCounter("GeneXusCounters", "StatementDirectSQLCount", "instance1", false);
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "WMI Performance countes error", e);
            }
        }
    static void Main(string[] args)
    {
        SimpleWriteInstance inst1 = new SimpleWriteInstance();

        inst1.name      = "Jeff";
        inst1.length    = 33;
        inst1.Published = true;
        Console.WriteLine("inst1 published");
        Console.ReadLine();
        inst1.Published = false;
        Console.WriteLine("inst1 revoked");

        Instrumentation.Publish(typeof(App));
        Console.WriteLine("Get ready to start");
        Console.ReadLine();
        NestedABC nest = new NestedABC();

        nest.Fire();
        MyInstanceABC abc = new MyInstanceABC();

        abc.Name = "Lauren";
        Instrumentation.Publish(abc);
//        abc.Published = true;
        Console.WriteLine("Get ready to end");
//        return;
        ManagementClass classNamespace = new ManagementClass("root:__NAMESPACE");
        IntPtr          ip             = (IntPtr)classNamespace;


#if xxx
        string[] installArgs = new String[] {
            "/logfile=",
            "/LogToConsole=false",
            "/ShowCallStack",
            typeof(App).Assembly.Location,
        };
        System.Configuration.Install.ManagedInstallerClass.InstallHelper(installArgs);
#endif

        Console.WriteLine("done");
        Beep1 beep = new Beep1();
        beep.tone  = 37;
        beep.tone2 = 55;
        beep.Fire();

        Beep2 beep2 = new Beep2();
        beep2.tone    = 1;
        beep2.tone2   = 3;
        beep2.xxx     = 12;
        beep2.yyy     = 31;
        beep2.str     = "Hello there";
        beep2.rg      = new int[3];
        beep2.rg[0]   = 73;
        beep2.rg[2]   = 88;
        beep2.embed   = new Embedded();
        beep2.embed.i = 987;
        beep2.embed.j = 654;

        beep2.embeds2      = new Embedded[4];
        beep2.embeds2[0]   = new Embedded();
        beep2.embeds2[0].i = 23;
        beep2.embeds2[0].j = 24;
        beep2.embeds2[1]   = new Embedded();
        beep2.embeds2[1].i = 25;
        beep2.embeds2[1].j = 26;
        beep2.embeds2[2]   = new Embedded();
        beep2.embeds2[2].i = 27;
        beep2.embeds2[2].j = 28;
        beep2.embeds2[3]   = new Embedded();
        beep2.embeds2[3].i = 29;
        beep2.embeds2[3].j = 30;


        beep2.embeds3      = new Embedded[3];
        beep2.embeds3[0]   = new Embedded();
        beep2.embeds3[0].i = 23;
        beep2.embeds3[0].j = 24;
        beep2.embeds3[2]   = new Embedded();
        beep2.embeds3[2].i = 27;
        beep2.embeds3[2].j = 28;

        beep2.Fire();

        ChangeEvent change = new ChangeEvent();

        Embedded embed = new Embedded();
        embed.i = 12;
        embed.j = 24;
        change.Fire();

        change.PreviousInstance = embed;
        change.Fire();

        change.TargetInstance = new OutterEmbedded();
        change.Fire();

        // PreviousInstance should be null
        change.PreviousInstance = new UnknownObject();
        change.Fire();

        // TargetInstance should be null
        change.TargetInstance = "how are you";
        change.Fire();

        // TargetInstance should be null
        change.TargetInstance = 37;
        change.Fire();

        change.TargetInstance = new ManagementObject("root:__Namespace.Name='cimv2'");
        change.Fire();

        new ComplexBeep().Fire();

        ManyThings things = new ManyThings();
        things.Fire();

        things.obj = new ManagementClass(@"root\cimv2:Win32_Process");
        things.Fire();

        things.obj     = new ManagementObject("root:__Namespace.Name='cimv2'");
        things.objects = new ManagementObject[] { new ManagementObject("root:__Namespace.Name='cimv2'"), new ManagementObject("root:__Namespace.Name='default'") };
        things.things  = new Object[] {};
        things.Fire();

        things.obj     = null;
        things.objects = null;
        things.things  = new Object[] { new OutterEmbedded(), new ManagementObject("root:__Namespace.Name='cimv2'") };
        things.Fire();

        things.things = new Object[] { new OutterEmbedded(), null, new ManagementObject("root:__Namespace.Name='cimv2'") };
        things.Fire();

        things.things  = null;
        things.objects = null;
        things.obj     = null;
        things.Fire();

        // BUG Wbem Test crashes if you try to view array of ManagementObjects!!!!!!!!!!!!!!!
        things.obj     = new ManagementClass();
        things.objects = new ManagementObject[] { new ManagementObject() };
        things.things  = new Object[] { new OutterEmbedded(), new ManagementObject(), new ManagementObject("root:__Namespace.Name='cimv2'") };
        things.Fire();

        DiverseEvent diverse = new DiverseEvent();
        diverse.dt  = DateTime.Now;
        diverse.ts2 = new TimeSpan(3, 2, 1, 5, 654);
        diverse.Fire();

        DiverseEvent2 diverse2 = new DiverseEvent2();
        diverse2.name = "hello";
        diverse2.i    = 74;
        diverse2.Fire();

        Console.WriteLine("fired");
        Console.WriteLine("press enter");
        Console.ReadLine();
        SimpleInstance  inst  = new SimpleInstance();
        DiverseInstance inst2 = new DiverseInstance();
        DiverseInstance inst3 = new DiverseInstance();
        inst.i    = 12;
        inst.name = "Lauren";

        inst.Published  = true;
        inst2.Published = true;
        inst3.Published = true;
        Console.WriteLine("published");
        Console.ReadLine();
        inst.Published  = false;
        inst2.Published = false;
        inst3.Published = false;
        Console.WriteLine("revoked");
        Console.ReadLine();
        inst.Published  = true;
        inst2.Published = true;
        inst3.Published = true;
        Console.WriteLine("published");
        Console.ReadLine();
        inst.Published  = false;
        inst2.Published = false;
        inst3.Published = false;
        Console.WriteLine("revoked");
        Console.ReadLine();
    }
 /// <summary>	Publish information. </summary>
 public void PublishInfo()
 {
     Instrumentation.Publish(this);
 }
Beispiel #26
0
        void InstallThreadHandler()
        {
            try
            {
                Trace.WriteLine("Thread");
                Assembly curAssm;
                curAssm = Assembly.GetAssembly(this.GetType());
                int  registertimeout = 0;
                bool wmiregistered   = false;
                while (registertimeout < 30 * 1000)
                {
                    Trace.WriteLine("Try to register WMI");
                    try
                    {
                        if (System.Management.Instrumentation.Instrumentation.IsAssemblyRegistered(curAssm))
                        {
                            //Cool; it's already registered in WMI
                            Trace.WriteLine("Already registered");
                            wmiregistered = true;
                            break;
                        }
                        else //Well then, register it
                        {
                            Trace.WriteLine("Ensure we are registered with WMI");

                            System.Management.Instrumentation.Instrumentation.RegisterAssembly(curAssm);
                            wmiregistered = true;
                            break;
                        }
                    }
                    catch (ManagementException)
                    {
                        Trace.WriteLine("Waiting for WMI to initialise");
                        Thread.Sleep(500);
                        registertimeout += 500;
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("WMI initialisation not finished (" + e.ToString() + ")");
                        Thread.Sleep(500);
                        registertimeout += 500;
                    }
                }
                if (!wmiregistered)
                {
                    Trace.WriteLine("Unable to contact WMI");
                    InstallState.Fail("Unable to contact WMI");
                }
                Trace.WriteLine("Got WMI connection");
                CitrixXenServerInstallStatus installstatusclass = new CitrixXenServerInstallStatus(InstallState);
                Trace.WriteLine("got status");
                try
                {
                    Instrumentation.Publish(installstatusclass);
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                    throw;
                }
                Trace.WriteLine("Begin");
                while (InstallState.PauseOnStart)
                {
                    Trace.WriteLine("Paused");
                    Thread.Sleep(1000);
                    try
                    {
                        int pausestate = (int)Application.CommonAppDataRegistry.GetValue("Continue", 0);
                        if (pausestate != 0)
                        {
                            break;
                        }
                    }
                    catch { };
                }
                ;
                InstallState.MaxProgress = 100;
                InstallState.Progress    = 1;
                Trace.WriteLine("Initializing Install =======================================");

                InstallerState.ExistingDriverInstalling = false;
                uint res = setupapi.CMP_WaitNoPendingInstallEvents(0);
                if (res == setupapi.WAIT_TIMEOUT || res == setupapi.WAIT_FAILED)
                {
                    InstallerState.ExistingDriverInstalling = true;
                    Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "existingDriverInstalling", 1, RegistryValueKind.DWord);
                }
                Trace.WriteLine("check reg");
                Object regval = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "existingDriverInstalling", 0);

                if (regval != null && ((int)regval) == 1)
                {
                    Trace.WriteLine("set from reg");
                    InstallerState.ExistingDriverInstalling = true;
                }
                Trace.WriteLine("reg done");

                DriverPackage DriversMsi;
                MsiInstaller  VssProvMsi;
                MsiInstaller  AgentMsi;
                string        installdir;
                NSISItem      InstallerNSIS;
                if (is64BitOS())
                {
                    Trace.WriteLine("64 Bit Install");
                    installdir = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "Install_Dir", Application.StartupPath);
                    DriversMsi = new DriverPackage((string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath), Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixxendriversx64.msi");
                    VssProvMsi = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixvssx64.msi");
                    AgentMsi   = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixguestagentx64.msi");

                    InstallerNSIS = new NSISItem("Citrix XenTools", (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath));
                }
                else
                {
                    Trace.WriteLine("32 Bit Install");
                    installdir = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "Install_Dir", Application.StartupPath);
                    DriversMsi = new DriverPackage((string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath), Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixxendriversx86.msi");
                    VssProvMsi = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixvssx86.msi");
                    AgentMsi   = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixguestagentx86.msi");

                    InstallerNSIS = new NSISItem("Citrix XenTools", (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath));
                }
                installdir = "\"" + installdir + "\"";

                VifConfig Vif = new VifConfig();
                Trace.WriteLine("Entering state loop");
                Dictionary <string, int[]> prog = new Dictionary <string, int[]>();

                prog["installscore"]     = new int[] { 300, 0 };
                prog["tempscore"]        = new int[] { 0, 0 };
                InstallState.MaxProgress = prog["installscore"][0];

                if (InstallService.isWOW64())
                {
                    Trace.WriteLine("Install failed");
                    InstallState.Fail("PV Tools cannot be installed on systems where .Net applications are forced to run under WoW64\n\nSet HKEY_LOCAL_MACHINE\\Software\\Microsoft\\.NetFramework\\Enable64Bit to 1 and attempt the install again.");
                }

                while ((!InstallState.Failed) && (InstallState.RebootCount > 0) && (!InstallState.Done))
                {
                    InstallState.Unchanged  = true;
                    prog["installscore"][1] = 0;
                    if (InstallState.GotAgent)
                    {
                        prog["installscore"][1] += 100;
                    }
                    if (InstallState.NsisFree)
                    {
                        prog["installscore"][1] += 100;
                    }
                    if (InstallState.GotDrivers)
                    {
                        prog["installscore"][1] += 100;
                    }
                    InstallState.MaxProgress = prog["installscore"][0] + prog["tempscore"][0];
                    InstallState.Progress    = prog["installscore"][1] + prog["tempscore"][1];

                    if (InstallState.GotAgent &&
                        ((InstallWizard.InstallerState.WinVersion.isServerSKU() && InstallState.GotVssProvider) || !InstallWizard.InstallerState.WinVersion.isServerSKU()) &&
                        InstallState.GotDrivers &&
                        !InstallState.RebootNow &&
                        InstallState.NsisFree &&
                        !InstallState.NeedsReboot)
                    {
                        Trace.WriteLine("Everything is installed");
                        InstallState.Installed = true;
                        InstallState.Done      = true;
                        continue;
                    }

                    if ((!InstallState.GotDrivers) && (InstallState.NsisFree))
                    {
                        Trace.WriteLine("Check if drivers are functioning");

                        string oldtext = InstallState.DriverText;

                        if ((DriversMsi.installed() && (!DriversMsi.olderinstalled())) && DriversMsi.functioning(ref InstallState.DriverText))
                        {
                            Trace.WriteLine("Drivers functioning");
                            InstallState.GotDrivers = true;
                        }
                        else
                        {
                            if (InstallState.DriverText != oldtext)
                            {
                                InstallState.PollingReset();
                            }
                            if ((!InstallState.DriversPlaced) && ((!DriversMsi.installed()) || DriversMsi.olderinstalled()))
                            {
                                Trace.WriteLine("Driver install package not found");
                                Trace.WriteLine("Attempt driver install");
                                Trace.WriteLine(DriversMsi.ToString());

                                if (DriversMsi.olderinstalled())
                                {
                                }

                                try
                                {
                                    DriversMsi.install("INSTALLDIR=" + installdir, "driversmsi", InstallState);
                                    InstallState.DriversPlaced = true;
                                    InstallState.NeedsReboot   = true;
                                    InstallState.Polling       = true;
                                    Trace.WriteLine("Install success");
                                    continue;
                                }
                                catch (InstallerException e)
                                {
                                    Trace.WriteLine("Install failed");
                                    InstallState.Fail("Failed to install drivers: " + e.ErrorMessage);
                                    continue;
                                }
                            }
                            else
                            {
                                if ((!InstallState.DriversPlaced) && InstallState.NotRebooted)
                                {
                                    DriversMsi.repair();
                                    Trace.WriteLine("Repair done");
                                    InstallState.DriversPlaced = true;
                                    InstallState.NeedsReboot   = true;
                                    InstallState.Polling       = true;
                                    continue;
                                }
                                else
                                {
                                    Trace.WriteLine("Repair not needed");
                                }
                            }
                            if (!InstallState.RebootNow)
                            {
                                Trace.WriteLine("Wait to see if drivers initialize");
                                int noneedtoreboot = (int)Application.CommonAppDataRegistry.GetValue("DriverFinalReboot", 0);
                                if (noneedtoreboot == 0)
                                {
                                    Trace.WriteLine("Pool - I don't know if I have to reboot");
                                    InstallState.Polling = true;
                                }
                                else
                                {
                                    Trace.WriteLine("Don't poll, I have to reboot");
                                    InstallState.RebootNow = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No DriverMSI work");
                    }


                    if ((!InstallState.NsisFree) && (!InstallState.NsisHandlingRequired))
                    {
                        Trace.WriteLine("Checking NSIS");
                        if (InstallerNSIS.installed() || InstallerNSIS.nsisPartiallyInstalled())
                        {
                            Trace.WriteLine("NSIS is installed, and needs to be removed");
                            if (InstallState.RebootReady)
                            {
                                Trace.WriteLine("Removing NSIS");
                                Vif.CopyPV();
                                Trace.WriteLine("Attempting NSIS Uninstall");
                                InstallState.NsisHandlingRequired = true;
                                InstallState.RebootNow            = true;
                            }
                            else
                            {
                                Trace.WriteLine("We'll remove NSIS next reboot");
                                InstallState.RebootNow = true;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("No NSIS based installer found");
                            InstallState.NsisFree = true;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No NSIS work");
                    }

                    if (DriverPackage.unknownDeviceInstalled())
                    {
                        InstallState.Fail("Unknown PV drivers installed on system.  Uninstall PV drivers and retry");
                        continue;
                    }


                    if (InstallWizard.InstallerState.WinVersion.isServerSKU())
                    {
                        if ((!InstallState.GotVssProvider) && (InstallState.NsisFree) && (!InstallState.NsisHandlingRequired))
                        {
                            Trace.WriteLine("Checking Vss Provider");
                            if (!VssProvMsi.installed())
                            {
                                Trace.WriteLine("Vss Provider not found, installing");
                                Trace.WriteLine(VssProvMsi.ToString());
                                try
                                {
                                    VssProvMsi.install("INSTALLDIR=" + installdir, "vssprov1msi", InstallState);
                                }
                                catch (InstallerException e)
                                {
                                    InstallState.Fail("Failed to install Vss  Provider : " + e.ErrorMessage);
                                    continue;
                                }
                            }
                            else if (VssProvMsi.olderinstalled())
                            {
                                Trace.WriteLine("Old Vss Provider found, updating");
                                try
                                {
                                    VssProvMsi.install("INSTALLDIR=" + installdir, "vssprov2msi", InstallState);
                                }
                                catch (InstallerException e)
                                {
                                    InstallState.Fail("Failed to install Vss Provider : " + e.ErrorMessage);
                                    continue;
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Correct Vss Provider found");
                                InstallState.GotVssProvider = true;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("No VSS Work");
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No ServerSKU Work");
                    }

                    if ((!InstallState.GotAgent) && (InstallState.NsisFree) && (!InstallState.NsisHandlingRequired))
                    {
                        Trace.WriteLine("Checking Agent");
                        if (!AgentMsi.installed())
                        {
                            Trace.WriteLine("Agent not found, installing");
                            Trace.WriteLine(AgentMsi.ToString());
                            try
                            {
                                AgentMsi.install("INSTALLDIR=" + installdir, "agent1msi", InstallState);
                            }
                            catch (InstallerException e)
                            {
                                InstallState.Fail("Failed to install Guest Agent : " + e.ErrorMessage);
                                continue;
                            }
                        }
                        else if (AgentMsi.olderinstalled())
                        {
                            Trace.WriteLine("Old Agent found, updating");
                            try
                            {
                                AgentMsi.install("INSTALLDIR=" + installdir, "agent2msi", InstallState);
                            }
                            catch (InstallerException e)
                            {
                                InstallState.Fail("Failed to install Guest Agent : " + e.ErrorMessage);
                                continue;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Correct Agent found");
                            InstallState.GotAgent = true;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No Agent Work");
                    }

                    if (InstallState.Polling)
                    {
                        if (InstallState.PollTimedOut)
                        {
                            Trace.WriteLine("Polling timed out");
                            InstallState.RebootNow   = true;
                            InstallState.NeedsReboot = false;
                            InstallState.Polling     = false;
                        }
                        else
                        {
                            prog["tempscore"][1] += 1;
                            prog["tempscore"][0] += 1;
                            InstallState.Sleep(5000);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No Polling Work");
                    }

                    if ((!InstallState.RebootReady) && InstallState.RebootNow && InstallState.Unchanged)
                    {
                        // We are ready to reboot
                        Trace.WriteLine("Is anything preventing us from shutting down?");
                        if (InstallerState.ExistingDriverInstalling)
                        {
                            setupapi.CMP_WaitNoPendingInstallEvents(1000 * 20 * 60);
                        }
                        else
                        {
                            setupapi.CMP_WaitNoPendingInstallEvents(setupapi.INFINITE);
                        }

                        Trace.WriteLine("Ready to reboot");
                        InstallState.Polling       = false;
                        InstallState.RebootDesired = true;
                        if (InstallState.WaitForShutdown())
                        {
                            Trace.WriteLine("Shutdown occuring");
                        }
                        continue;
                    }
                    else
                    {
                        Trace.WriteLine("No rebootready work");
                    }

                    if (InstallState.RebootReady && InstallState.RebootNow && InstallState.Unchanged)
                    {
                        Trace.WriteLine("Expecting Reboot /  Shutdown");
                        InstallState.Rebooting = true;
                        if (InstallState.NsisHandlingRequired)
                        {
                            // Irritatingly, the NSIS installer continues running for longer than the
                            // lifetime of the uninstall.exe process.  Since we don't want to reboot
                            // while it (or its unattached children) are still running, we rely on
                            // the NSIS uninstaller to perform its own reboot, when it is done.
                            //
                            // We want to update George or earlier installers, as they don't
                            // uninstall silently
                            if (InstallerNSIS.installed() &&
                                ((InstallerNSIS.majorVersion() > 5) ||
                                 ((InstallerNSIS.majorVersion() == 5) && (InstallerNSIS.minorVersion() > 5))))
                            {
                                InstallerNSIS.uninstall();
                            }
                            else
                            {
                                // NSIS is installed, but the install is corrupt and the uninstaller can't be located
                                InstallerNSIS.update();

                                //NSIS returns the same errorlevel for 'failure to install' and for
                                // 'needs a reboot to install'.  So we have to presume the install
                                // was a success.
                            }
                            InstallState.RebootNow = false;
                            InstallState.Done      = true;
                        }
                        else
                        {
                            InstallState.Done      = true;
                            InstallState.RebootNow = false;
                            InstallState.DoShutdown();
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No Shutdown work");
                    }
                }

                Trace.WriteLine("Exited install cycle " + InstallState.Failed + " " + InstallState.RebootCount + " " + InstallState.Done);

                if (!InstallState.Passive)
                {
                    // We want to wait until the user terminates the GUI installer before shutting down the service
                    InstallState.WaitForDone();
                }

                if (InstallState.Installed || InstallState.Cancelled || InstallState.Failed)
                {
                    Trace.WriteLine("Installed " + InstallState.Installed + " Cancelled " + InstallState.Cancelled + " Failed " + InstallState.Failed);

                    try
                    {
                        Registry.LocalMachine.OpenSubKey(@"Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run", true).DeleteValue("CitrixXenAgentInstaller");
                    }
                    catch (Exception e)
                    {
                        if (!InstallState.Passive)
                        {
                            Trace.WriteLine("Failed to remove install agent run subkey: " + e.ToString());
                            InstallState.Fail("Failed to remove install agent subkey");
                        }
                    }
                    Trace.WriteLine("Turn off DriverFinalReboot");
                    Application.CommonAppDataRegistry.SetValue("DriverFinalReboot", 0);

                    try
                    {
                        Registry.LocalMachine.OpenSubKey(@"HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", true).DeleteValue("existingDriverInstalling");
                    }
                    catch
                    {
                    }

                    Registry.SetValue(@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\XenPVInstall", "Start", 3);
                    (new Thread(delegate()
                    {
                        this.Stop();
                    })).Start();
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Install exception :" + e.ToString());
                InstallState.Fail("Failed to install due to exception" + e.ToString());
                if (!InstallState.Passive)
                {
                    // We want to wait until the user terminates the GUI installer before shutting down the service

                    InstallState.WaitForDone();
                }
                try
                {
                    Registry.LocalMachine.OpenSubKey(@"Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run", true).DeleteValue("CitrixXenAgentInstaller");
                }
                catch {
                    Trace.WriteLine("Failed to remove install agent run subkey (error state)");
                    InstallState.Fail("Failed to remove install agent subkey");
                }
            }
        }
Beispiel #27
0
 public WMIProcedure(string name)
 {
     this.name = name;
     Instrumentation.Publish(this);
 }
Beispiel #28
0
 public WMISentence(DataStoreProviderInfo dsInfo, String name)
 {
     sentenceInfo          = dsInfo.GetSentenceInfo(name);
     sentenceInfo.sentence = this;
     Instrumentation.Publish(this);
 }
Beispiel #29
0
        void InstallThreadHandler()
        {
            try
            {
                Trace.WriteLine("Thread");
                Assembly curAssm;
                curAssm = Assembly.GetAssembly(this.GetType());
                int  registertimeout = 0;
                bool wmiregistered   = false;
                while (registertimeout < 30 * 1000)
                {
                    Trace.WriteLine("Try to register WMI");
                    try
                    {
                        if (System.Management.Instrumentation.Instrumentation.IsAssemblyRegistered(curAssm))
                        {
                            //Cool; it's already registered in WMI
                            Trace.WriteLine("Already registered");
                            wmiregistered = true;
                            break;
                        }
                        else //Well then, register it
                        {
                            Trace.WriteLine("Ensure we are registered with WMI");

                            System.Management.Instrumentation.Instrumentation.RegisterAssembly(curAssm);
                            wmiregistered = true;
                            break;
                        }
                    }
                    catch (ManagementException)
                    {
                        Trace.WriteLine("Waiting for WMI to initialise");
                        Thread.Sleep(500);
                        registertimeout += 500;
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("WMI initialisation not finished (" + e.ToString() + ")");
                        Thread.Sleep(500);
                        registertimeout += 500;
                    }
                }
                if (!wmiregistered)
                {
                    Trace.WriteLine("Unable to contact WMI");
                    InstallState.Fail("Unable to contact WMI");
                }
                Trace.WriteLine("Got WMI connection");
                CitrixXenServerInstallStatus installstatusclass = new CitrixXenServerInstallStatus(InstallState);
                Trace.WriteLine("got status");
                try
                {
                    Instrumentation.Publish(installstatusclass);
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                    throw;
                }
                Trace.WriteLine("Begin");
                while (InstallState.PauseOnStart)
                {
                    Trace.WriteLine("Paused");
                    Thread.Sleep(1000);
                    try
                    {
                        int pausestate = (int)Application.CommonAppDataRegistry.GetValue("Continue", 0);
                        if (pausestate != 0)
                        {
                            break;
                        }
                    }
                    catch { };
                }
                ;
                InstallState.MaxProgress = 100;
                InstallState.Progress    = 1;
                Trace.WriteLine("Initializing Install =======================================");


                HwidState     HWID = new HwidState(@"PCI\VEN_5853&DEV_0002&REV_02");
                DriverPackage DriversMsi;
                MsiInstaller  VssProvMsi;
                MsiInstaller  AgentMsi;
                string        installdir;
                NSISItem      InstallerNSIS;
                if (is64BitOS())
                {
                    Trace.WriteLine("64 Bit Install");
                    installdir = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "Install_Dir", Application.StartupPath);
                    DriversMsi = new DriverPackage((string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath), Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixxendriversx64.msi");
                    VssProvMsi = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixvssx64.msi");
                    AgentMsi   = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixguestagentx64.msi");

                    InstallerNSIS = new NSISItem("Citrix XenTools", (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath));
                }
                else
                {
                    Trace.WriteLine("32 Bit Install");
                    installdir = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "Install_Dir", Application.StartupPath);
                    DriversMsi = new DriverPackage((string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath), Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixxendriversx86.msi");
                    VssProvMsi = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixvssx86.msi");
                    AgentMsi   = new MsiInstaller(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath) + "citrixguestagentx86.msi");

                    InstallerNSIS = new NSISItem("Citrix XenTools", (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "MSISourceDir", Application.StartupPath));
                }
                installdir = "\"" + installdir + "\"";

                VifConfig Vif = new VifConfig();
                Trace.WriteLine("Entering state loop");
                Dictionary <string, int[]> prog = new Dictionary <string, int[]>();

                prog["installscore"]     = new int[] { 300, 0 };
                prog["tempscore"]        = new int[] { 0, 0 };
                InstallState.MaxProgress = prog["installscore"][0];

                if (InstallService.isWOW64())
                {
                    Trace.WriteLine("Install failed");
                    InstallState.Fail("PV Tools cannot be installed on systems where .Net applications are forced to run under WoW64\n\nSet HKEY_LOCAL_MACHINE\\Software\\Microsoft\\.NetFramework\\Enable64Bit to 1 and attempt the install again.");
                }

                while ((!InstallState.Failed) && (InstallState.RebootCount > 0) && (!InstallState.Done))
                {
                    InstallState.Unchanged  = true;
                    prog["installscore"][1] = 0;
                    if (InstallState.GotAgent)
                    {
                        prog["installscore"][1] += 100;
                    }
                    if (InstallState.NsisFree)
                    {
                        prog["installscore"][1] += 100;
                    }
                    if (InstallState.GotDrivers)
                    {
                        prog["installscore"][1] += 100;
                    }
                    InstallState.MaxProgress = prog["installscore"][0] + prog["tempscore"][0];
                    InstallState.Progress    = prog["installscore"][1] + prog["tempscore"][1];

                    if (InstallState.GotAgent &&
                        ((InstallWizard.InstallerState.WinVersion.isServerSKU() && InstallState.GotVssProvider) || !InstallWizard.InstallerState.WinVersion.isServerSKU()) &&
                        InstallState.GotDrivers &&
                        !InstallState.RebootNow &&
                        InstallState.NsisFree &&
                        !InstallState.NeedsReboot)
                    {
                        Trace.WriteLine("Everything is installed");
                        InstallState.Installed = true;
                        InstallState.Done      = true;

                        /* try
                         * {
                         *  // Registry.LocalMachine.OpenSubKey(@"Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run",true).DeleteValue("CitrixXenAgentInstaller");
                         * }
                         * catch (Exception e){
                         *   Trace.WriteLine("Failed to remove install agent run subkey: " + e.ToString());
                         *   InstallState.Fail("Failed to remove install agent run subkey: " + e.ToString());
                         *   continue;
                         * }*/
                        continue;
                    }



                    if ((!InstallState.GotDrivers) && (InstallState.NsisFree) && (!HWID.needsupdate()))
                    {
                        Trace.WriteLine("Check if drivers are functioning");

                        string oldtext = InstallState.DriverText;

                        if ((DriversMsi.installed() && (!DriversMsi.olderinstalled())) && DriversMsi.functioning(ref InstallState.DriverText))
                        {
                            Trace.WriteLine("Drivers functioning");
                            InstallState.GotDrivers = true;
                        }
                        else
                        {
                            if (InstallState.DriverText != oldtext)
                            {
                                InstallState.PollingReset();
                            }
                            if ((!InstallState.DriversPlaced) && ((!DriversMsi.installed()) || DriversMsi.olderinstalled()))
                            {
                                Trace.WriteLine("Driver install package not found");
                                Trace.WriteLine("Attempt driver install");
                                Trace.WriteLine(DriversMsi.ToString());

                                if (DriversMsi.olderinstalled())
                                {
                                    Vif.CopyNewPVWorkaround();
                                }

                                try
                                {
                                    DriversMsi.install("INSTALLDIR=" + installdir, "driversmsi", InstallState);
                                    InstallState.DriversPlaced = true;
                                    InstallState.NeedsReboot   = true;
                                    InstallState.Polling       = true;
                                    Trace.WriteLine("Install success");
                                    continue;
                                }
                                catch (InstallerException e)
                                {
                                    Trace.WriteLine("Install failed");
                                    InstallState.Fail("Failed to install drivers: " + e.ErrorMessage);
                                    continue;
                                }
                            }
                            else
                            {
                                if ((!InstallState.DriversPlaced) && InstallState.NotRebooted)
                                {
                                    DriversMsi.repair();
                                    Trace.WriteLine("Repair done");
                                    InstallState.DriversPlaced = true;
                                    InstallState.NeedsReboot   = true;
                                    InstallState.Polling       = true;
                                    continue;
                                }
                                else
                                {
                                    Trace.WriteLine("Repair not needed");
                                }
                            }
                            if (!InstallState.RebootNow)
                            {
                                Trace.WriteLine("Wait to see if drivers initialize");
                                int noneedtoreboot = (int)Application.CommonAppDataRegistry.GetValue("DriverFinalReboot", 0);
                                if (noneedtoreboot == 0)
                                {
                                    Trace.WriteLine("Pool - I don't know if I have to reboot");
                                    InstallState.Polling = true;
                                }
                                else
                                {
                                    Trace.WriteLine("Don't poll, I have to reboot");
                                    InstallState.RebootNow = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No DriverMSI work");
                    }


                    if ((!InstallState.NsisFree) && (!InstallState.NsisUninstalling))
                    {
                        Trace.WriteLine("Checking NSIS");
                        if (InstallerNSIS.installed())
                        {
                            Trace.WriteLine("NSIS is installed, and needs to be removed");
                            if (InstallState.RebootReady)
                            {
                                Trace.WriteLine("Removing NSIS");
                                Vif.CopyPV();
                                Trace.WriteLine("Attempting NSIS Uninstall");
                                InstallState.NsisUninstalling = true;
                                InstallState.RebootNow        = true;
                            }
                            else
                            {
                                Trace.WriteLine("We'll remove NSIS next reboot");
                                InstallState.RebootNow = true;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("No NSIS based installer found");
                            if (HWID.needsupdate())
                            {
                                Vif.CopyPV();
                                Trace.WriteLine("Attempting legacy Install");
                                try
                                {
                                    RegistryKey classes = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Class");
                                    foreach (String classuuid in classes.GetSubKeyNames())
                                    {
                                        Trace.WriteLine("Examining " + classuuid);
                                        RegistryKey classkey = classes.OpenSubKey(classuuid, true);
                                        string[]    filters  = (string[])classkey.GetValue("UpperFilters");
                                        if (filters != null)
                                        {
                                            Trace.WriteLine("UpperFilters Exists");
                                            List <string> newfilters = new List <String>();
                                            foreach (String filter in filters)
                                            {
                                                if (filter.ToUpper() != "XENFILT")
                                                {
                                                    newfilters.Add(filter);
                                                }
                                                else
                                                {
                                                    Trace.WriteLine("Removing XENFILT");
                                                }
                                            }
                                            if (newfilters.Count > 0)
                                            {
                                                if (newfilters.Count < filters.Length)
                                                {
                                                    Trace.WriteLine("Updating UpperFilters");
                                                    classkey.SetValue("UpperFilters", newfilters.ToArray(), RegistryValueKind.MultiString);
                                                }
                                            }
                                            else
                                            {
                                                classkey.DeleteValue("UpperFilters");
                                            }
                                        }
                                        else
                                        {
                                            Trace.WriteLine("UpperFilters not found");
                                        }
                                    }
                                }
                                catch
                                {
                                    Trace.WriteLine("Removing xenfilt from UpperFilters entries failed");
                                }
                                if (DriversMsi.installed())
                                {
                                    DriversMsi.uninstall();
                                }
                                if (AgentMsi.installed())
                                {
                                    AgentMsi.uninstall();
                                }

                                InstallState.NsisUninstalling = true;
                                InstallState.RebootNow        = true;
                            }
                            InstallState.NsisFree = true;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No NSIS work");
                    }

                    if (InstallWizard.InstallerState.WinVersion.isServerSKU())
                    {
                        if ((!InstallState.GotVssProvider) && (InstallState.NsisFree) && (!InstallState.NsisUninstalling))
                        {
                            Trace.WriteLine("Checking Vss Provider");
                            if (!VssProvMsi.installed())
                            {
                                Trace.WriteLine("Vss Provider not found, installing");
                                Trace.WriteLine(VssProvMsi.ToString());
                                try
                                {
                                    VssProvMsi.install("INSTALLDIR=" + installdir, "vssprov1msi", InstallState);
                                }
                                catch (InstallerException e)
                                {
                                    InstallState.Fail("Failed to install Vss  Provider : " + e.ErrorMessage);
                                    continue;
                                }
                            }
                            else if (VssProvMsi.olderinstalled())
                            {
                                Trace.WriteLine("Old Vss Provider found, updating");
                                try
                                {
                                    VssProvMsi.install("INSTALLDIR=" + installdir, "vssprov2msi", InstallState);
                                }
                                catch (InstallerException e)
                                {
                                    InstallState.Fail("Failed to install Vss Provider : " + e.ErrorMessage);
                                    continue;
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Correct Vss Provider found");
                                InstallState.GotVssProvider = true;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("No VSS Work");
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No ServerSKU Work");
                    }

                    if ((!InstallState.GotAgent) && (InstallState.NsisFree) && (!InstallState.NsisUninstalling))
                    {
                        Trace.WriteLine("Checking Agent");
                        if (!AgentMsi.installed())
                        {
                            Trace.WriteLine("Agent not found, installing");
                            Trace.WriteLine(AgentMsi.ToString());
                            try
                            {
                                AgentMsi.install("INSTALLDIR=" + installdir, "agent1msi", InstallState);
                            }
                            catch (InstallerException e)
                            {
                                InstallState.Fail("Failed to install Guest Agent : " + e.ErrorMessage);
                                continue;
                            }
                        }
                        else if (AgentMsi.olderinstalled())
                        {
                            Trace.WriteLine("Old Agent found, updating");
                            try
                            {
                                AgentMsi.install("INSTALLDIR=" + installdir, "agent2msi", InstallState);
                            }
                            catch (InstallerException e)
                            {
                                InstallState.Fail("Failed to install Guest Agent : " + e.ErrorMessage);
                                continue;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Correct Agent found");
                            InstallState.GotAgent = true;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No Agent Work");
                    }

                    if (InstallState.Polling)
                    {
                        if (InstallState.PollTimedOut)
                        {
                            Trace.WriteLine("Polling timed out");
                            InstallState.RebootNow   = true;
                            InstallState.NeedsReboot = false;
                            InstallState.Polling     = false;
                        }
                        else
                        {
                            prog["tempscore"][1] += 1;
                            prog["tempscore"][0] += 1;
                            InstallState.Sleep(5000);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No Polling Work");
                    }

                    if ((!InstallState.RebootReady) && InstallState.RebootNow && InstallState.Unchanged)
                    {
                        // We are ready to reboot
                        Trace.WriteLine("Ready to reboot");
                        InstallState.Polling       = false;
                        InstallState.RebootDesired = true;
                        if (InstallState.WaitForShutdown())
                        {
                            Trace.WriteLine("Shutdown occuring");
                        }
                        continue;
                    }
                    else
                    {
                        Trace.WriteLine("No rebootready work");
                    }

                    if (InstallState.RebootReady && InstallState.RebootNow && InstallState.Unchanged)
                    {
                        Trace.WriteLine("Expecting Reboot /  Shutdown");
                        InstallState.Rebooting = true;
                        if (InstallState.NsisUninstalling)
                        {
                            // We have to do the HWID check before NSIS is uninstalled, but
                            // when we know NSIS is about to be uninstalled.
                            //
                            // NSIS leads to a blue screen if it doesn't have the right HWID at start of day
                            //
                            if ((!InstallState.GotDrivers) && (!InstallState.HWIDCorrect))
                            {
                                Trace.WriteLine("Checking HWID");
                                if (HWID.needsupdate())
                                {
                                    Trace.WriteLine("HWID Needs updating");
                                    try
                                    {
                                        if (!HWID.update())
                                        {
                                            InstallState.Fail("Unable to enable Xeniface WMI Client when trying to change device id");
                                        }
                                        Trace.WriteLine("HWID should be changed following next reboot");
                                    }
                                    catch (ManagementException)
                                    {
                                        //This suggests we don't have a WMI interface.  update nsis and try again
                                        InstallState.NsisUninstalling = false;
                                    }
                                }
                                else
                                {
                                    Trace.WriteLine("Correct HWID Found");
                                    InstallState.HWIDCorrect = true;
                                }
                            }
                            // Irritatingly, the NSIS installer continues running for longer than the
                            // lifetime of the uninstall.exe process.  Since we don't want to reboot
                            // while it (or its unattached children) are still running, we rely on
                            // the NSIS uninstaller to perform its own reboot, when it is done.
                            if (InstallState.NsisUninstalling)
                            {
                                InstallerNSIS.uninstall();
                            }
                            else
                            {
                                //DriverPackage.addcerts(InstallerNSIS.path);
                                InstallerNSIS.update();

                                //NSIS returns the same errorlevel for 'failure to install' and for
                                // 'needs a reboot to install'.  So we have to presume the install
                                // was a success.
                            }
                            InstallState.RebootNow = false;
                            InstallState.Done      = true;
                        }
                        else
                        {
                            InstallState.Done      = true;
                            InstallState.RebootNow = false;
                            InstallState.DoShutdown();
                        }
                    }
                    else
                    {
                        Trace.WriteLine("No Shutdown work");
                    }
                }

                Trace.WriteLine("Exited install cycle " + InstallState.Failed + " " + InstallState.RebootCount + " " + InstallState.Done);

                if (!InstallState.Passive)
                {
                    // We want to wait until the user terminates the GUI installer before shutting down the service
                    InstallState.WaitForDone();
                }

                if (InstallState.Installed || InstallState.Cancelled || InstallState.Failed)
                {
                    Trace.WriteLine("Installed " + InstallState.Installed + " Cancelled " + InstallState.Cancelled + " Failed " + InstallState.Failed);

                    try
                    {
                        Registry.LocalMachine.OpenSubKey(@"Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run", true).DeleteValue("CitrixXenAgentInstaller");
                    }
                    catch (Exception e)
                    {
                        if (!InstallState.Passive)
                        {
                            Trace.WriteLine("Failed to remove install agent run subkey: " + e.ToString());
                            InstallState.Fail("Failed to remove install agent subkey");
                        }
                    }
                    Trace.WriteLine("Turn off DriverFinalReboot");
                    Application.CommonAppDataRegistry.SetValue("DriverFinalReboot", 0);
                    Registry.SetValue(@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\XenPVInstall", "Start", 3);
                    (new Thread(delegate()
                    {
                        this.Stop();
                    })).Start();
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Install exception :" + e.ToString());
                InstallState.Fail("Failed to install due to exception" + e.ToString());
                if (!InstallState.Passive)
                {
                    // We want to wait until the user terminates the GUI installer before shutting down the service

                    InstallState.WaitForDone();
                }
                try
                {
                    Registry.LocalMachine.OpenSubKey(@"Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run", true).DeleteValue("CitrixXenAgentInstaller");
                }
                catch {
                    Trace.WriteLine("Failed to remove install agent run subkey (error state)");
                    InstallState.Fail("Failed to remove install agent subkey");
                }
            }
        }