Beispiel #1
0
        private void instAppsWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string machine = machineBigBox.Text;

            insttarget = machine;
            Console.WriteLine("instAppsWorker_DoWork begin: " + machine);
            BackgroundWorker worker = sender as BackgroundWorker;

            worker.ReportProgress(0, "Installed Applications - Connecting to Registry Hives... ");
            //Console.WriteLine("Service list:\n" + Machine.ListServices(machine, ".*"));

            bool withWMI = true;

            if (withWMI)
            {
                worker.ReportProgress(0, "Installed Applications - Querying WMI...");
                int n = 0; MachineInfo.GetInstalledAppsWMI(machine,
                                                           row => { worker.ReportProgress(50, row); return(n++); },
                                                           () => e.Cancel = worker.CancellationPending,
                                                           null, null, false, AuditSecGUIForm.DESIRED_APPS);
            }
            else
            {
                bool remregrun = MachineInfo.isServiceRunning(machine, "RemoteRegistry");
                if (!machineBigBox.Text.Equals(machine))
                {
                    return;
                }
                if (!remregrun)
                {
                    worker.ReportProgress(0, "Installed Applications - Starting Remote Registry...");
                    MachineInfo.StartService(machine, "RemoteRegistry", 30000);
                }
                if (MachineInfo.isServiceRunning(machine, "RemoteRegistry"))
                {
                    worker.ReportProgress(0, "Installed Applications - Querying Registry Hives...");
                    int n = 0; MachineInfo.GetInstalledAppsREG(machine,
                                                               row => { worker.ReportProgress(50, row); return(n++); },
                                                               () => e.Cancel = worker.CancellationPending,
                                                               false, AuditSecGUIForm.DESIRED_APPS);
                }
                else
                {
                    worker.ReportProgress(100, "Installed Applications - Registry Hives not available.");
                }
                if (!remregrun)
                {
                    worker.ReportProgress(100, "Installed Applications - Stopping Remote Registry...");
                    MachineInfo.StopService(machine, "RemoteRegistry", 30000);
                }
            }
            worker.ReportProgress(100, "Installed Applications - " + (e.Cancel ? "Incomplete" : "Complete"));
            Console.WriteLine("instAppsWorker_DoWork finish: " + machine + " - " + (e.Cancel ? "Incomplete" : "Complete"));
        }