Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            startWatch = new ManagementEventWatcher(
                new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
            startWatch.EventArrived += new EventArrivedEventHandler(startWatch_EventArrived);
            startWatch.Start();
            stopWatch = new ManagementEventWatcher(
                new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"));
            stopWatch.EventArrived += new EventArrivedEventHandler(stopWatch_EventArrived);
            stopWatch.Start();

            MenuStripLanguageBulgarian.Enabled = false;//default language is BG
            MenuStripLanguageEnglish.Enabled   = true;

            res_man = new ResourceManager("Optimizer.Resource.Res", typeof(Form1).Assembly);
            switch_language();

            string        Today = DateTime.Now.ToShortDateString();
            List <string> DisplayName;
            List <string> DisplayName64;
            List <string> Location;
            List <string> Location64;

            InstalledPrograms.GetInstalledProgramsFromRegistry(RegistryView.Registry32, out DisplayName, out Location);
            InstalledPrograms.GetInstalledProgramsFromRegistry(RegistryView.Registry64, out DisplayName64, out Location64);
            DisplayName.AddRange(DisplayName64);
            AllDisplayName = DisplayName;
            Location.AddRange(Location64);
            AllLocation = Location;

            newDoc      = new CreateExcelDoc("Table.xls");//Create excel doc
            ExcelMatrix = newDoc.ReadMatrix();
            if (ExcelMatrix.GetLength(0) <= 1)
            {
                newDoc.AddArrayInCol(0, 1, DisplayName.ToArray());
                newDoc.NewDate(Today, DisplayName.Count + 1);
                ExcelMatrix = newDoc.ReadMatrix();
            }
            else
            {
                if (ExcelMatrix.GetLength(0) == DisplayName.Count + 1)
                {
                    newDoc.NewDate(Today, DisplayName.Count + 1);
                }
            }


            string[,] newExcelMatrix = new string[AllDisplayName.Count() + 1, 8];
            Array.Copy(ExcelMatrix, newExcelMatrix, 8);
            for (int i = 0; i < AllDisplayName.Count(); i++)
            {
                newExcelMatrix[i + 1, 0] = AllDisplayName[i];

                for (int p = 0; p < ExcelMatrix.GetLength(0); p++)
                {
                    if (newExcelMatrix[i + 1, 0] == ExcelMatrix[p, 0])
                    {
                        newExcelMatrix[i + 1, 1] = ExcelMatrix[p, 1];
                        newExcelMatrix[i + 1, 2] = ExcelMatrix[p, 2];
                        newExcelMatrix[i + 1, 3] = ExcelMatrix[p, 3];
                        newExcelMatrix[i + 1, 4] = ExcelMatrix[p, 4];
                        newExcelMatrix[i + 1, 5] = ExcelMatrix[p, 5];
                        newExcelMatrix[i + 1, 6] = ExcelMatrix[p, 6];
                        newExcelMatrix[i + 1, 7] = ExcelMatrix[p, 7];
                        break;
                    }
                    else if (p == (ExcelMatrix.GetLength(0) - 1))
                    {
                        newExcelMatrix[i + 1, 1] = "0";
                        newExcelMatrix[i + 1, 2] = "0";
                        newExcelMatrix[i + 1, 3] = "0";
                        newExcelMatrix[i + 1, 4] = "0";
                        newExcelMatrix[i + 1, 5] = "0";
                        newExcelMatrix[i + 1, 6] = "0";
                        newExcelMatrix[i + 1, 7] = "0";
                    }
                }
            }
            ExcelMatrix = newExcelMatrix;

            process = new GetProcess();
            int ProcesCount = process.GetAllProcesses().GetLength(0);

            SProcess = process.GetAllProcesses();
            ListView1();
            ListView2();
            ListView3(ExcelMatrix);
            ListView4();
        }