예제 #1
0
 /// <summary>
 /// Gets information about the computer currently connected to. 
 /// </summary>
 /// <returns></returns>
 public ComputerInfo Computer()
 {
     if (_computer != null) return _computer;
     var result = GetObjects("Win32_ComputerSystem");
     return _computer = result.Select(ComputerInfo.CreateComputerInfo).FirstOrDefault();
 }
예제 #2
0
        protected internal static ComputerInfo CreateComputerInfo(ManagementObject managementObject)
        {
            if (managementObject == null)
                return null;
            ComputerInfo comp = null;
            try
            {
                comp = new ComputerInfo();
                comp._managementObject = managementObject;
                comp.Caption = (string)managementObject["Caption"];
                comp.Description = (string)managementObject["Description"];
                comp.DNSHostName = (string)managementObject["DNSHostName"];
                comp.Domain = (string)managementObject["Domain"];

                comp.Manufacturer = (string)managementObject["Manufacturer"];
                comp.Model = (string)managementObject["Model"];
                comp.Name = (string)managementObject["Name"];
                comp.NameFormat = (string)managementObject["NameFormat"];
                comp.NumberOfLogicalProcessors = (UInt32)managementObject["NumberOfLogicalProcessors"];
                comp.NumberOfProcessors = (UInt32)managementObject["NumberOfProcessors"];

                comp.PrimaryOwnerContact = (string)managementObject["PrimaryOwnerContact"];
                comp.PrimaryOwnerName = (string)managementObject["PrimaryOwnerName"];
                comp.Status = (string)managementObject["Status"];
                comp.SystemType = (string)managementObject["SystemType"];
                comp.TotalPhysicalMemory = (UInt64)managementObject["TotalPhysicalMemory"];
                comp.UserName = (string)managementObject["UserName"];
                comp.Workgroup = (string)managementObject["Workgroup"];
                comp.DomainRole = (DomainRole)(ushort)(managementObject["DomainRole"]);
                comp.PartOfDomain = (bool?)managementObject["PartOfDomain"];
            }
            catch (Exception ex)
            {
                Trace.WriteLine("ERROR: " + ex.Message);
                Trace.TraceError(ex.ToString());
            }
            return comp;
        }