Пример #1
0
        public RAM()
        {
            var iter = WMIQuery.WMIExecQuery(WMIQuery.RAM.Query).GetEnumerator();

            while (iter.MoveNext())
            {
                var wmi = iter.Current;
                Speed        = wmi[WMIQuery.RAM.Speed].ToString();
                Voltage      = wmi[WMIQuery.RAM.ConfiguredVoltage].ToString().Insert(1, ".");
                Manufacturer = wmi[WMIQuery.RAM.Manufacturer].ToString();
            }
            PysicalSize = info.TotalPhysicalMemory;
            VirtualSize = info.TotalVirtualMemory;
        }
Пример #2
0
        public CPU()
        {
            var iter = WMIQuery.WMIExecQuery(WMIQuery.CPU.Query).GetEnumerator();

            while (iter.MoveNext())
            {
                var wmi = iter.Current;
                Name         = wmi[WMIQuery.CPU.Name].ToString().Trim();
                CurrentClock = Convert.ToInt32(wmi[WMIQuery.CPU.MaxClock]);
                Voltage      = Convert.ToDouble(wmi[WMIQuery.CPU.Voltage]) / 10;
                L2CacheSize  = Convert.ToInt32(wmi[WMIQuery.CPU.L2CacheSize]);
                L3CacheSize  = Convert.ToInt32(wmi[WMIQuery.CPU.L3CacheSize]);
                CoreCount    = Convert.ToInt32(wmi[WMIQuery.CPU.NumberOfCores]);
                ThreadCount  = Convert.ToInt32(wmi[WMIQuery.CPU.ThreadCount]);
            }
        }
Пример #3
0
        public DetailDisk()
        {
            /*DiskPartitions = WMIQuery.WMIExecQuery(WMIQuery.Disk.LogicalToPartitionQuery)
             *  .GroupBy(
             *      p => int.Parse(Regex.Match(p["Antecedent"].ToString(), @"(?<=Disk #)\d+").Value), // physical disk index
             *      p => Regex.Match(p["Dependent"].ToString(), "(?<=DeviceID=\").*?(?=\")").Value)   // device id (Volume label)
             *  .ToDictionary(
             *      g => g.Key,
             *      g => g.ToArray());
             *
             * LogicalDisks = WMIQuery.WMIExecQuery(WMIQuery.Disk.LogicalDiskQuery)
             *  .ToDictionary(
             *      d => d["DeviceID"].ToString(), // device id
             *      d => d);*/

            DiskDrives = WMIQuery.WMIExecQuery(WMIQuery.Disk.DiskDriveQuery)
                         .OrderBy(d => d["Index"].ToString()) // disk index
                         .ToArray();
        }
Пример #4
0
        public GPU()
        {
            var iter = WMIQuery.WMIExecQuery(WMIQuery.GPU.Query).GetEnumerator();

            while (iter.MoveNext())
            {
                var wmi = iter.Current;
                AdapterCompatiability = wmi[WMIQuery.GPU.AdapterCompatibility].ToString();
                AdapterRAM            = wmi[WMIQuery.GPU.AdapterRAM].ToString();
                Caption              = wmi[WMIQuery.GPU.Caption].ToString();
                CurrentRefreshRate   = wmi[WMIQuery.GPU.CurrentRefreshRate].ToString();
                DriverDate           = wmi[WMIQuery.GPU.DriverDate].ToString();
                DriverVersion        = wmi[WMIQuery.GPU.DriverVersion].ToString();
                MaxRefreshRate       = wmi[WMIQuery.GPU.MaxRefreshRate].ToString();
                MinRefreshRate       = wmi[WMIQuery.GPU.MinRefreshRate].ToString();
                VideoModeDescription = wmi[WMIQuery.GPU.VideoModeDescription].ToString();
                VideoProcessor       = wmi[WMIQuery.GPU.VideoProcessor].ToString();
            }
            DriverDate = DriverDate.Split('.')[0];
        }
Пример #5
0
        public void GetLoggedInUser()
        {
            var userName = WMIQuery.GetLoggedOnLocalUser(SystemManager.Computer);

            if (userName.Equals("No users currently logged on.") || userName.Equals("Unable to query remote machine.  Try again later."))
            {
                isUserLoggedOn = false;
                DisplayedName  = userName;
            }
            else if (ADQuery.isDomainAccount(userName) == true)
            {
                isUserLoggedOn  = true;
                isDomainAccount = true;
                DisplayedName   = userName;
                User            = ADQuery.GetUserByUserName(userName.Split('\\')[1]);
            }
            else
            {
                DisplayedName = SystemManager.Computer.Name + "\\" + userName;
            }
        }
Пример #6
0
        public OS()
        {
            String[] MUI;
            var      iter = WMIQuery.WMIExecQuery(WMIQuery.OS.Query).GetEnumerator();

            while (iter.MoveNext())
            {
                var wmi = iter.Current;
                Caption         = wmi[WMIQuery.OS.Caption].ToString();
                Architecture    = wmi[WMIQuery.OS.Architecture].ToString();
                BuildNumber     = wmi[WMIQuery.OS.BuildNumber].ToString();
                Version         = wmi[WMIQuery.OS.Version].ToString();
                SerialNumber    = wmi[WMIQuery.OS.SerialNumber].ToString();
                LastBootUpTime  = wmi[WMIQuery.OS.LastBootUpTime].ToString();
                ContryCode      = wmi[WMIQuery.OS.CountryCode].ToString();
                CurrentTimeZone = wmi[WMIQuery.OS.CurrentTimeZone].ToString();
                MUI             = (String[])wmi[WMIQuery.OS.MUILanguages];
                Language        = wmi[WMIQuery.OS.Language].ToString();
                InstallTime     = ManagementDateTimeConverter.ToDateTime(wmi[WMIQuery.OS.InstallDate].ToString());
                MUILanguages    = String.Join(", ", MUI);
            }
        }
Пример #7
0
        private void RegCollector_Load(object sender, EventArgs e)
        {
            queries.Clear();
            table.Columns.Clear();
            table.Columns.Add("C0", "Machine");
            WMIQuery q;

            queries.Add(q = new WMIQuery("USB Printers", MachineInfo.getUSBPrinters));
            table.Columns.Add("C" + table.Columns.Count, q.name);

            queries.Add(q = new WMIQuery("USB Storage", MachineInfo.getUSBStorage));
            table.Columns.Add("C" + table.Columns.Count, q.name);

            table.AutoResizeColumns();

            this.Text = "Multiple WMI Values Collector";

            TargetButton.Visible = true;
            if (table.Columns.Count > 0)
            {
                xls_in.ShowDialog();
            }
        }
        protected override ServiceListDataItem[] GetOutputData(DataItemBase[] inputDataItems)
        {
            try
            {
                string opMessages = "";
                bool   IsCluster  = false;
                if (supportClusteredService)
                {
                    IsCluster = ServiceHelper.IsCluster(".");
                }
                long computerUpTimeMin = 0;
                if (supportDelayedStart)
                {
                    computerUpTimeMin = ComputerHelper.GetUptime(".") / 60;
                }

                // get all clustered services and their on-line statuses
                List <ClusteredServiceInfo> clusteredServices = new List <ClusteredServiceInfo>();
                if (IsCluster)
                {
                    try
                    {
                        using (WMIQuery query = new WMIQuery(new ManagementScope("\\\\.\\root\\MSCluster"), "SELECT * FROM MSCluster_Resource"))
                        {
                            foreach (ManagementBaseObject serviceData in query.Select())
                            {
                                if (serviceData["Type"].ToString() != "Generic Service")
                                {
                                    continue;
                                }
                                clusteredServices.Add(new ClusteredServiceInfo
                                {
                                    nodeName           = serviceData["OwnerNode"].ToString(),
                                    serviceDisplayName = serviceData["Name"].ToString(),
                                    serviceName        = ((ManagementBaseObject)serviceData["PrivateProperties"])["ServiceName"].ToString(),
                                    Offline            = (uint)serviceData["State"] == 3
                                });
                                serviceData.Dispose();
                            }
                        }
                    }
                    catch (Exception cluster_e)
                    {
                        string msg = "Failed to query clustered services information.";
                        ModuleErrorSignalReceiver(ModuleErrorSeverity.DataLoss, ModuleErrorCriticality.Continue, cluster_e, msg);
                        opMessages += msg + "; ";
                    }
                }

                // list all services
                List <ServiceInfo> allServices        = new List <ServiceInfo>();
                StringComparer     ignoreCaseComparer = StringComparer.OrdinalIgnoreCase;
                foreach (ServiceController service in string.IsNullOrWhiteSpace(QueryService) ? ServiceController.GetServices() : new ServiceController[] { new ServiceController(QueryService) })
                {
                    try
                    {
                        ServiceInfo newInstance = new ServiceInfo()
                        {
                            IsClustered = clusteredServices.Exists(x => ignoreCaseComparer.Compare(x.serviceName, service.ServiceName) == 0),
                            NodeName    = ComputerHelper.GetMachineDNSName(), // default to local host
                            DisplayName = service.DisplayName,
                            Name        = service.ServiceName,
                            Status      = service.Status.ToString(),
                            Type        = (int)service.ServiceType,
                        };
                        FillServiceValuesFromRegistry(newInstance, service, QueryParameters);
                        if (newInstance.IsClustered)
                        {
                            newInstance.NodeName         = clusteredServices.Find(x => ignoreCaseComparer.Compare(x.serviceName, service.ServiceName) == 0).nodeName;
                            newInstance.IsClusterOffline = clusteredServices.Find(x => ignoreCaseComparer.Compare(x.serviceName, service.ServiceName) == 0).Offline;
                        }
                        allServices.Add(newInstance);
                    }
                    catch (Exception e)
                    {
                        ModuleErrorSignalReceiver(ModuleErrorSeverity.DataLoss, ModuleErrorCriticality.Continue, e, $"Failure while reading service {service.DisplayName}. Skipping.");
                    }
                    finally
                    {
                        service.Dispose();
                    }
                }

                // query advanced dependency
                ServiceController[] allNativeServices = null;
                if (QueryParameters)
                {
                    try
                    {
                        allNativeServices = ServiceController.GetServices();
                        foreach (ServiceInfo resultService in allServices)
                        {
                            ServiceController nativeServiceInstance = allNativeServices.Where(ns => ns.ServiceName == resultService.Name).FirstOrDefault();
                            if (nativeServiceInstance == null)
                            {
                                continue; // if the service was deleted right before the second query
                            }
                            if (nativeServiceInstance.ServicesDependedOn != null)
                            {
                                resultService.DependOn = new List <DependOnRecord>();
                                foreach (ServiceController dep_on in nativeServiceInstance.ServicesDependedOn)
                                {
                                    resultService.DependOn.Add(GetDependOnRecord(dep_on));
                                }
                            }
                            if (nativeServiceInstance.DependentServices != null)
                            {
                                resultService.Dependant = new List <DependOnRecord>();
                                foreach (ServiceController dep in nativeServiceInstance.DependentServices)
                                {
                                    resultService.Dependant.Add(GetDependantRecord(dep));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ModuleErrorSignalReceiver(ModuleErrorSeverity.DataLoss, ModuleErrorCriticality.Continue, e, $"Failure while walking through service dependencies. Skipping.");
                    }
                }
                finally
                {
                    if (allNativeServices != null)
                    {
                        foreach (ServiceController ns in allNativeServices)
                        {
                            try { ns.Dispose(); } catch { }
                        }
                    }
                }

                return(new ServiceListDataItem[]
                {
                    new ServiceListDataItem(new ServiceList
                    {
                        Services = allServices,
                        ErrorCode = 0,
                        ErrorMessage = opMessages
                    })
                });
            }
        private async void SetSystemInformation(bool isOnline)
        {
            if (isOnline)
            {
                string formFactor   = "";
                string biosVersion  = "";
                string makeModel    = "";
                string serialNumber = "";
                string OS           = "";
                _view.TypeValueLabel      = "loading...";
                _view.BIOSValueLabel      = "loading...";
                _view.MakeModelValueLabel = "loading...";
                _view.SerialValueLabel    = "loading...";
                _view.OSValueLabel        = "loading...";
                await Task.Run(() =>
                {
                    if (isOnline)
                    {
                        try
                        {
                            formFactor   = WMIQuery.GetFormFactor(Computer.Name);
                            biosVersion  = WMIQuery.GetBIOSVersion(Computer.Name);
                            makeModel    = WMIQuery.GetMakeModel(Computer.Name);
                            serialNumber = WMIQuery.GetSystemSerialNumber(Computer.Name);
                            OS           = WMIQuery.GetOSVersion(Computer.Name);
                        }
                        catch (Exception e)
                        {
                            _view.DisplayMessage(e.Message, "Set System Info Error");
                        }
                    }
                });

                if (String.IsNullOrEmpty(formFactor))
                {
                    _view.TypeValueLabel = "unavailable.";
                }
                else
                {
                    _view.TypeValueLabel = formFactor;
                }
                if (String.IsNullOrEmpty(biosVersion))
                {
                    _view.BIOSValueLabel = "unavailable.";
                }
                else
                {
                    _view.BIOSValueLabel = biosVersion;
                }
                if (String.IsNullOrEmpty(makeModel))
                {
                    _view.MakeModelValueLabel = "unavailable.";
                }
                else
                {
                    _view.MakeModelValueLabel = makeModel;
                }
                if (String.IsNullOrEmpty(serialNumber))
                {
                    _view.SerialValueLabel = "unavailable.";
                }
                else
                {
                    _view.SerialValueLabel = serialNumber;
                }
                if (String.IsNullOrEmpty(OS))
                {
                    _view.OSValueLabel = "unavailable.";
                }
                else
                {
                    _view.OSValueLabel = OS;
                }
            }
            else
            {
                _view.TypeValueLabel      = "";
                _view.BIOSValueLabel      = "";
                _view.MakeModelValueLabel = "";
                _view.SerialValueLabel    = "";
                _view.OSValueLabel        = "";
            }
        }
Пример #10
0
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            string graphicsCardPath = GetRegistrySetting("graphicsCardPath");
            string pciRootClassRaw  = GetRegistrySetting("pciRootClass");
            string pciRootPath      = GetRegistrySetting("pciRootPath");

            try
            {
                graphicsCardPath = GetRegistrySetting("graphicsCardPath");
                pciRootClassRaw  = GetRegistrySetting("pciRootClass");
                pciRootPath      = GetRegistrySetting("pciRootPath");
            }
            catch (Exception ex)
            {
                base.EventLog.WriteEntry(string.Format("Error while Reading Settings: {0}", ex), EventLogEntryType.Error);
            }

            if (!IsNullOrEmptyOrWhiteSpace(graphicsCardPath))
            {
                foreach (dynamic graphicsCard in WMIQuery.GetAllObjects(Win32.VideoController))
                {
                    if (graphicsCard.Status == "Error" && graphicsCard.ConfigManagerErrorCode == 43)
                    {
                        base.EventLog.WriteEntry(string.Format("VideoController found with Error 43: Name:\"{0}\", DeviceID:\"{1}\"", graphicsCard.Name, graphicsCard.PNPDeviceID), EventLogEntryType.Information);

                        if (graphicsCard.PNPDeviceID == graphicsCardPath)
                        {
                            if (!IsNullOrEmptyOrWhiteSpace(pciRootClassRaw))
                            {
                                if (!IsNullOrEmptyOrWhiteSpace(pciRootPath))
                                {
                                    //Guid pciRootClass = new Guid("{4d36e97d-e325-11ce-bfc1-08002be10318}");
                                    //Guid pciRootClass = new Guid(pciRootClassRaw);

                                    if (Guid.TryParse(pciRootClassRaw, out Guid pciRootClass))
                                    {
                                        try
                                        {
                                            base.EventLog.WriteEntry("Disabling Device...");
                                            DisableDevice.DeviceHelper.SetDeviceEnabled(pciRootClass, pciRootPath, false);
                                        }
                                        catch (Exception ex)
                                        {
                                            base.EventLog.WriteEntry(string.Format("Disabling Device failed: {0}", ex), EventLogEntryType.Error);
                                            //base.Stop();
                                            //return;
                                        }

                                        try
                                        {
                                            base.EventLog.WriteEntry("Enabling Device...");
                                            DisableDevice.DeviceHelper.SetDeviceEnabled(pciRootClass, pciRootPath, true);
                                        }
                                        catch (Exception ex)
                                        {
                                            base.EventLog.WriteEntry(string.Format("Enabling Device failed: {0}", ex), EventLogEntryType.Error);
                                            //base.Stop();
                                            //return;
                                        }
                                    }
                                    else
                                    {
                                        base.EventLog.WriteEntry("Couldnt parse \"pciRootClassRaw\" GUID", EventLogEntryType.Warning);
                                    }
                                }
                                else
                                {
                                    base.EventLog.WriteEntry("\"pciRootPath\" is empty, null or whitespace", EventLogEntryType.Warning);
                                }
                            }
                            else
                            {
                                base.EventLog.WriteEntry("\"pciRootClassRaw\" is empty, null or whitespace", EventLogEntryType.Warning);
                            }
                        }
                    }
                }
            }
            else
            {
                base.EventLog.WriteEntry("\"graphicsCardPath\" is empty, null or whitespace", EventLogEntryType.Warning);
            }

            this.timer.Start();
        }