Пример #1
0
        static int Main()
        {
            List <int>   UIRunningInSession = new List <int>();
            const string PackageID          = "Vulpes-SDCA1-Update";
            string       dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (dir.EndsWith("\\") == false)
            {
                dir += "\\";
            }

            string pkgfile = dir + "agentupdate.foxpkg";

            if (File.Exists(pkgfile) == false)
            {
                return(1);
            }

            PackageInstaller pkgi = new PackageInstaller();
            string           Error;

            if (pkgi.PackageInfo(pkgfile, null, out Error) == false)
            {
                FoxEventLog.WriteEventLog("Self-Update: Error reading package file " + pkgfile + ": " + Error, EventLogEntryType.Error);
                return(2);
            }

            if (pkgi.PackageInfoData.PackageID != PackageID)
            {
                FoxEventLog.WriteEventLog("Self-Update: PackageID mismatch on file " + pkgfile, EventLogEntryType.Error);
                return(3);
            }

            FileVersionInfo fv         = FileVersionInfo.GetVersionInfo(dir + "FoxSDC_Agent.exe");
            Int64           sdcversion = Convert.ToInt64(fv.FileBuildPart.ToString("0000") + fv.FilePrivatePart.ToString("0000"));

            if (pkgi.PackageInfoData.VersionID <= sdcversion)
            {
                FoxEventLog.WriteEventLog("Self-Update: Version on package is same or older than installed for file " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + fv.ToString(), EventLogEntryType.Error);
                return(4);
            }

            ServiceController svc = new ServiceController("FoxSDCA");

            try
            {
                svc.Stop();
            }
            catch
            {
            }

            int i = 0;

            do
            {
                i++;
                if (i > 120 * 4)
                {
                    break;
                }
                svc.Refresh();
                Thread.Sleep(1000);
            } while (svc.Status != ServiceControllerStatus.Stopped);

            #region Kill Processes

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent_ui.exe")
                    {
                        if (UIRunningInSession.Contains(proc.SessionId) == false)
                        {
                            UIRunningInSession.Add(proc.SessionId);
                        }
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_applyusersettings.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            #endregion

            FoxEventLog.WriteEventLog("Self-Update: Updating from " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + sdcversion.ToString(), EventLogEntryType.Information);

            PKGStatus      status;
            PKGRecieptData reciept;

            if (pkgi.InstallPackage(pkgfile, null, PackageInstaller.InstallMode.Test, false, out Error, out status, out reciept, "FoxSDC_Selfupdate.exe") == false)
            {
                FoxEventLog.WriteEventLog("Self-Update: Error testing the package file " + pkgfile + ": " + Error, EventLogEntryType.Error);
                svc = new ServiceController("FoxSDCA");
                svc.Start();
                return(5);
            }

            if (pkgi.InstallPackage(pkgfile, null, PackageInstaller.InstallMode.Install, false, out Error, out status, out reciept, "FoxSDC_Selfupdate.exe") == false)
            {
                FoxEventLog.WriteEventLog("Self-Update: Error installing the package file " + pkgfile + ": " + Error, EventLogEntryType.Error);
                svc = new ServiceController("FoxSDCA");
                svc.Start();
                return(6);
            }

            FoxEventLog.WriteEventLog("Self-Update: Completed updating from " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + sdcversion.ToString(), EventLogEntryType.Information);

            svc = new ServiceController("FoxSDCA");
            svc.Start();

            try
            {
                File.Delete(pkgfile);
            }
            catch
            {
                CommonUtilities.PendingMove(pkgfile, null);
            }

            SessionStarter.StartProgramInSessions(dir.ToLower() + "foxsdc_agent_ui.exe", UIRunningInSession);

            return(0);
        }
Пример #2
0
        void ApplyPolicy(WSUSPolicy p)
        {
            if (p.ConfigureWSUS == null)
            {
                return;
            }
            if (p.StatusServer == null)
            {
                p.SpecifyStatusServer = null;
            }
            if (p.WUServer == null)
            {
                p.SpecifyWUServer = null;
            }
            if (string.IsNullOrWhiteSpace(p.Target) == true)
            {
                p.SpecifyClientSideTargeting = false;
            }

            if (p.ConfigureWSUS == true)
            {
                using (RegistryKey regDOD = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Policies\\Microsoft\\Windows\\DeliveryOptimization"))
                {
                    if (regDOD == null || regDOD == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot write Delivery Optimization Registry Settings", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    if (p.EnableDownloadMode == true)
                    {
                        regDOD.SetValue("DODownloadMode", p.DownloadMode, RegistryValueKind.DWord);
                    }
                    else
                    {
                        regDOD.DeleteValue("DODownloadMode", false);
                    }
                }

                using (RegistryKey regWU = Registry.LocalMachine.CreateSubKey("Software\\Policies\\Microsoft\\Windows\\WindowsUpdate"))
                {
                    using (RegistryKey regAU = Registry.LocalMachine.CreateSubKey("Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU"))
                    {
                        if (regWU == null || regAU == null)
                        {
                            FoxEventLog.WriteEventLog("Cannot write Windows Update Registry Settings", System.Diagnostics.EventLogEntryType.Error);
                            return;
                        }
                        if (p.SpecifyWUOptions == true)
                        {
                            regAU.SetValue("AUOptions", p.WUOptions, RegistryValueKind.DWord);
                        }
                        else
                        {
                            regAU.DeleteValue("AUOptions", false);
                        }

                        if (p.InstallDuringMaintenance != null)
                        {
                            regAU.SetValue("AutomaticMaintenanceEnabled", p.InstallDuringMaintenance == true ? 1 : 0, RegistryValueKind.DWord);
                        }

                        if (p.SpecifyScheduleInstall == true)
                        {
                            regAU.SetValue("ScheduledInstallDay", p.ScheduleInstallDay, RegistryValueKind.DWord);
                            regAU.SetValue("ScheduledInstallTime", p.ScheduleInstallHour, RegistryValueKind.DWord);
                        }
                        if (p.SpecifyScheduleInstall == false)
                        {
                            regAU.DeleteValue("ScheduledInstallDay", false);
                            regAU.DeleteValue("ScheduledInstallTime", false);
                        }

                        if (p.InstallMicrosoftUpdates != null)
                        {
                            regAU.SetValue("AllowMUUpdateService", p.InstallMicrosoftUpdates == true ? 1 : 0, RegistryValueKind.DWord);
                        }
                        if (p.SpecifyWUServer != null)
                        {
                            regAU.SetValue("UseWUServer", p.SpecifyWUServer == true ? 1 : 0, RegistryValueKind.DWord);
                            if (p.SpecifyWUServer == true)
                            {
                                regWU.SetValue("WUServer", p.WUServer.Trim(), RegistryValueKind.String);
                                if (p.SpecifyStatusServer == true)
                                {
                                    regWU.SetValue("WUStatusServer", p.StatusServer.Trim(), RegistryValueKind.String);
                                }
                            }
                            else
                            {
                                regWU.DeleteValue("WUServer", false);
                                regWU.DeleteValue("WUStatusServer", false);
                            }
                        }
                        if (p.SpecifyClientSideTargeting != null)
                        {
                            regWU.SetValue("TargetGroupEnabled", p.SpecifyClientSideTargeting == true ? 1 : 0, RegistryValueKind.DWord);
                        }
                        if (p.SpecifyClientSideTargeting == true)
                        {
                            regWU.SetValue("TargetGroup", p.Target.Trim(), RegistryValueKind.String);
                        }
                        if (p.SpecifyClientSideTargeting == false)
                        {
                            regWU.DeleteValue("TargetGroup", false);
                        }
                        if (p.NoMSServer != null)
                        {
                            regWU.SetValue("DoNotConnectToWindowsUpdateInternetLocations", p.NoMSServer == true ? 1 : 0, RegistryValueKind.DWord);
                        }
                        if (p.SpecifyDetectionFreq != null)
                        {
                            regAU.SetValue("DetectionFrequencyEnabled", p.SpecifyDetectionFreq == true ? 1 : 0, RegistryValueKind.DWord);
                            if (p.SpecifyDetectionFreq == true)
                            {
                                regAU.SetValue("DetectionFrequency", p.DetectionFreq, RegistryValueKind.DWord);
                            }
                            if (p.SpecifyDetectionFreq == false)
                            {
                                regAU.DeleteValue("DetectionFrequency", false);
                            }
                        }
                        if (p.DontAutoRestart != null)
                        {
                            regAU.SetValue("NoAutoRebootWithLoggedOnUsers", p.DontAutoRestart == true ? 1 : 0, RegistryValueKind.DWord);
                        }
                        if (p.SpecifyAlwaysAutoRestart != null)
                        {
                            regAU.SetValue("AlwaysAutoRebootAtScheduledTime", p.SpecifyAlwaysAutoRestart == true ? 1 : 0, RegistryValueKind.DWord);
                            if (p.SpecifyAlwaysAutoRestart == true)
                            {
                                regAU.SetValue("AlwaysAutoRebootAtScheduledTime_Minutes", p.AlwaysAutoRestartDelay, RegistryValueKind.DWord);
                            }
                            else
                            {
                                regAU.DeleteValue("AlwaysAutoRebootAtScheduledTime_Minutes", false);
                            }
                        }
                        if (p.SpecifyDeadline != null)
                        {
                            regWU.SetValue("SetAutoRestartDeadline", p.SpecifyDeadline == true ? 1 : 0, RegistryValueKind.DWord);
                            if (p.SpecifyDeadline == true)
                            {
                                regWU.SetValue("AutoRestartDeadlinePeriodInDays", p.DeadLine, RegistryValueKind.DWord);
                            }
                            else
                            {
                                regWU.DeleteValue("AutoRestartDeadlinePeriodInDays", false);
                            }
                        }
                        if (p.DontAutoRestartDuringActiveHours != null)
                        {
                            regWU.SetValue("SetActiveHours", p.DontAutoRestartDuringActiveHours == true ? 1 : 0, RegistryValueKind.DWord);
                            if (p.DontAutoRestartDuringActiveHours == true)
                            {
                                regWU.SetValue("ActiveHoursStart", p.ActiveHoursFrom, RegistryValueKind.DWord);
                                regWU.SetValue("ActiveHoursEnd", p.ActiveHoursTo, RegistryValueKind.DWord);
                            }
                            else
                            {
                                regWU.DeleteValue("ActiveHoursStart", false);
                                regWU.DeleteValue("ActiveHoursEnd", false);
                            }
                        }
                        if (p.DisableDualScan != null)
                        {
                            regWU.SetValue("DisableDualScan", p.DisableDualScan == true ? 1 : 0, RegistryValueKind.DWord);
                        }
                        else
                        {
                            regWU.DeleteValue("DisableDualScan", false);
                        }
                    }
                }
            }
            if (p.ConfigureWSUS == false)
            {
                Registry.LocalMachine.DeleteSubKeyTree("Software\\Policies\\Microsoft\\Windows\\WindowsUpdate", false);
                Registry.LocalMachine.DeleteSubKeyTree("Software\\Policies\\Microsoft\\Windows\\DeliveryOptimization", false);
            }
        }
Пример #3
0
        static void PushThread()
        {
            Network      net = null;
            PushDataRoot pd;
            int          Crashes = 0;

            do
            {
                try
                {
                    if (net == null)
                    {
                        net = Utilities.ConnectNetwork(-1);
                    }

                    if (net == null)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push2: no connection", System.Diagnostics.EventLogEntryType.Information);
                        for (int i = 0; i < WaitNoConnection; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }
                    pd = net.GetPushData2();
                    if (pd == null)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push2: pd==null", System.Diagnostics.EventLogEntryType.Information);
                        for (int i = 0; i < WaitPDisNULL; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        pd = net.GetPushData2();
                        if (pd == null)
                        {
                            net = null;
                            FoxEventLog.VerboseWriteEventLog("Push2: pd==null - 2nd time - resetting connection", System.Diagnostics.EventLogEntryType.Information);
                            for (int i = 0; i < WaitPDisNULL2; i++)
                            {
                                Thread.Sleep(1000);
                                if (StopThread == true)
                                {
                                    return;
                                }
                            }
                            continue;
                        }
                    }
                    if (ApplicationCertificate.Verify(pd) == false)
                    {
                        FoxEventLog.WriteEventLog("Push2: One or more PushData were tampered - no PushData will be processed.", System.Diagnostics.EventLogEntryType.Error);
                        for (int i = 0; i < WaitTamperIssue; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }
                    Crashes = 0;

                    if (pd.Data.Action == "repeat")
                    {
                        if (StopThread == true)
                        {
                            return;
                        }
                        FoxEventLog.VerboseWriteEventLog("Push2: repeat", System.Diagnostics.EventLogEntryType.Information);
                        continue;
                    }
                    if (pd.Data.Action == "quit")
                    {
                        FoxEventLog.VerboseWriteEventLog("Push2: quit", System.Diagnostics.EventLogEntryType.Information);
                        net = null;
                        for (int i = 0; i < WaitQuit; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }

                    Thread a = new Thread(new ParameterizedThreadStart(PushThreadActionRunner));
                    PushDataForThreadRunner t = new PushDataForThreadRunner();
                    t.net = net.CloneElement2();
                    t.p   = pd.Data;
                    a.Start(t);
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.ToString());
                    FoxEventLog.VerboseWriteEventLog("Push2: SEH internally", System.Diagnostics.EventLogEntryType.Information);
                    Crashes++;
                    if (Crashes > 3)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push2: Resetting connection due too many crashes", System.Diagnostics.EventLogEntryType.Information);
                        net     = null;
                        Crashes = 0;
                    }
                    for (int i = 0; i < WaitCrash; i++)
                    {
                        Thread.Sleep(1000);
                        if (StopThread == true)
                        {
                            return;
                        }
                    }
                }
            } while (StopThread == false);
        }
Пример #4
0
        static int Main()
        {
            FoxEventLog.Shutup = true;
            string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (dir.EndsWith("\\") == false)
            {
                dir += "\\";
            }

            ProgramAgent.Init();

            if (ProgramAgent.LoadDLL() == false)
            {
                return(1);
            }

            if (SystemInfos.CollectSystemInfo() != 0)
            {
                return(1);
            }

            if (ApplicationCertificate.LoadCertificate() == false)
            {
                FoxEventLog.WriteEventLog("Cannot load certificate", System.Diagnostics.EventLogEntryType.Error);
                return(1);
            }

            if (FilesystemData.LoadCertificates() == false)
            {
                return(1);
            }
            if (FilesystemData.LoadPolicies() == false)
            {
                return(1);
            }
            FilesystemData.LoadLocalPackageData();
            FilesystemData.LoadLocalPackages();
            FilesystemData.LoadUserPackageData();
            FilesystemData.LoadEventLogList();

            FoxEventLog.Shutup = false;

            if (SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.Uninstall) == false)
            {
                return(5);
            }

            ServiceController svc = new ServiceController("FoxSDCA");

            try
            {
                svc.Stop();
            }
            catch
            {
            }

            int i = 0;

            do
            {
                i++;
                if (i > 120 * 4)
                {
                    break;
                }
                svc.Refresh();
                Thread.Sleep(1000);
            } while (svc.Status != ServiceControllerStatus.Stopped);

            #region Kill Processes

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent_ui.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_applyusersettings.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            #endregion

            try
            {
                RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                reg.DeleteValue("FoxSDCAgent", false);
                reg.DeleteValue("FoxSDCAgentApply", false);
                reg.Close();
            }
            catch
            {
            }

            try
            {
                Process.Start(Environment.ExpandEnvironmentVariables("%systemroot%\\system32\\msiexec.exe"), "/x {A6F066EE-E795-4C65-8FE4-2D93AB52BC36} /passive");
            }
            catch
            {
            }
            return(0);
        }
Пример #5
0
        public static void FinaliseApplyPolicy(List <PortMappingPolicy> Add, List <PortMappingPolicy> Remove)
        {
            Add    = DeDup(Add);
            Remove = DeDup(Remove);

            foreach (PortMappingPolicy rm in Remove)
            {
                bool DontRemove = false;
                //check if this policy is in "add" (to prevent connection breaking)
                foreach (PortMappingPolicy ad in Add)
                {
                    if (rm.BindTo0000 == ad.BindTo0000 && rm.ClientPort == ad.ClientPort &&
                        rm.EditHOSTS == ad.EditHOSTS && rm.HOSTSEntry == ad.HOSTSEntry &&
                        rm.ID == ad.ID && rm.NoBindIfSDCServerIsDetected == ad.NoBindIfSDCServerIsDetected)
                    {
                        DontRemove = true;
                        break;
                    }
                }
                if (DontRemove == true)
                {
                    continue;
                }

                PortMappings_ConnectionNode RMC = null;

                foreach (PortMappings_ConnectionNode C in Connections)
                {
                    if (C.RunningPort == rm.ClientPort && C.PolicyID == rm.ID)
                    {
                        RMC = C;
                        break;
                    }
                }

                if (RMC != null)
                {
                    Connections.Remove(RMC);
                    RMC.StopConnection();
                }
            }

            for (int i = 0; i < Add.Count; i++)
            {
                bool BadPort         = false;
                PortMappingPolicy ad = Add[i];
                for (int j = 0; j < Add.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (ad.ClientPort == Add[j].ClientPort)
                    {
                        FoxEventLog.WriteEventLog("Portmapping: Port " + ad.ClientPort + " conflicts with Policy ID " + ad.ID + " and " + Add[j].ID, EventLogEntryType.Error);
                        BadPort = true;
                        break;
                    }
                }
                if (BadPort == true)
                {
                    continue;
                }

                foreach (PortMappings_ConnectionNode cc in Connections)
                {
                    if (ad.ID == cc.PolicyID)
                    {
                        if (cc.PolicyData.BindTo0000 == ad.BindTo0000 && cc.PolicyData.ClientPort == ad.ClientPort &&
                            cc.PolicyData.EditHOSTS == ad.EditHOSTS && cc.PolicyData.HOSTSEntry == ad.HOSTSEntry &&
                            cc.PolicyData.NoBindIfSDCServerIsDetected == ad.NoBindIfSDCServerIsDetected)
                        {
                            //no changes - continue
                            BadPort = true;
                            break;
                        }
                        else
                        {
                            //remove connection
                            Connections.Remove(cc);
                            cc.StopConnection();
                            break;
                        }
                    }
                }
                if (BadPort == true)
                {
                    continue;
                }

                if (NetworkUtilities.PortAvailable(ad.ClientPort) == false)
                {
                    FoxEventLog.WriteEventLog("Portmapping: Port " + ad.ClientPort + " from Policy ID " + ad.ID + " is unavailable.", EventLogEntryType.Error);
                    continue;
                }

                if (ad.NoBindIfSDCServerIsDetected == true)
                {
                    bool FoundSDCS = false;
                    using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\FoxSDCS"))
                    {
                        if (reg != null)
                        {
                            FoundSDCS = true;
                        }
                    }
                    if (FoundSDCS == true)
                    {
                        continue;
                    }
                }

                if (ad.EditHOSTS == true)
                {
                    if (string.IsNullOrWhiteSpace(ad.HOSTSEntry) == false)
                    {
                        foreach (string HOSTS in ad.HOSTSEntry.Split('|'))
                        {
                            if (string.IsNullOrWhiteSpace(HOSTS) == true)
                            {
                                continue;
                            }
                            HostsEdit.AppendIntoHOSTSFile(HOSTS.Trim(), "127.0.0.1");
                        }
                    }
                }

                PortMappings_ConnectionNode C = new PortMappings_ConnectionNode(ad);
                C.StartConnection();
                Connections.Add(C);
            }
        }
Пример #6
0
        static int Main(string[] args)
        {
            foreach (string arg in args)
            {
                if (arg.ToLower() == "-nopackages")
                {
                    NoPackages = true;
                }
            }

            FoxEventLog.Shutup = true;

            ProgramAgent.Init();

            if (ProgramAgent.LoadDLL() == false)
            {
                return(1);
            }

            FoxEventLog.Shutup = false;
#if !DEBUG
            List <string> Additionals = new List <string>();
            Additionals.Add(Assembly.GetExecutingAssembly().Location);
            if (ProgramAgent.TestIntegrity(Additionals) == false)
            {
                FoxEventLog.WriteEventLog("Apply User settings: Integrity failed!", EventLogEntryType.Error, true);
                return(1);
            }
#endif

            FoxEventLog.Shutup = true;

            if (SystemInfos.CollectSystemInfo() != 0)
            {
                return(1);
            }

            if (ApplicationCertificate.LoadCertificate() == false)
            {
                FoxEventLog.Shutup = false;
                FoxEventLog.WriteEventLog("Apply User settings: Cannot load certificate", System.Diagnostics.EventLogEntryType.Error);
                return(1);
            }

            FoxEventLog.Shutup = false;

            if (FilesystemData.LoadCertificates(true) == false)
            {
                return(1);
            }
            if (FilesystemData.LoadPolicies() == false)
            {
                return(1);
            }
            FilesystemData.LoadLocalPackageData();
            FilesystemData.LoadLocalPackages();
            FilesystemData.LoadUserPackageData();
            FilesystemData.LoadEventLogList();

            SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplyUser);

            if (NoPackages == true)
            {
                return(0);
            }

            string PackagesFolder = SystemInfos.ProgramData + "Packages\\";
            if (Directory.Exists(PackagesFolder) == false)
            {
                return(2);
            }

            foreach (PackagesToInstall pkg in FilesystemData.LocalPackages)
            {
                LocalPackageData lpkg = FilesystemData.FindLocalPackageFromListLatest(pkg.PackageID);
                if (lpkg == null)
                {
                    continue;
                }
                if (pkg.Version != lpkg.Version)
                {
                    continue;
                }

                PackageInstaller inst     = new PackageInstaller();
                string           metafile = PackagesFolder + pkg.MetaFilename;
                if (File.Exists(metafile) == false)
                {
                    continue;
                }
                string         Error;
                PKGRecieptData Reciept;
                PKGStatus      res;
                if (inst.InstallPackage(metafile, PackageCertificate.ActivePackageCerts, PackageInstaller.InstallMode.ApplyUserSettingsTest, true, out Error, out res, out Reciept) == false)
                {
                    FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be tested: " + Error, System.Diagnostics.EventLogEntryType.Error);
                    continue;
                }
                FoxEventLog.VerboseWriteEventLog("Apply User settings: Applying user settings for " + pkg.MetaFilename, EventLogEntryType.Information);
                if (inst.ApplyUserSettings(metafile, PackageCertificate.ActivePackageCerts, out Error, out res) == false)
                {
                    FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be used to apply user settings: " + Error, System.Diagnostics.EventLogEntryType.Error);
                    continue;
                }
            }

            if (RegistryData.Verbose == 1)
            {
                FoxEventLog.VerboseWriteEventLog("Apply User settings: ApplyUserSettings success for " + Environment.UserDomainName + "\\" + Environment.UserName, EventLogEntryType.Information);
            }

            return(0);
        }