Example #1
0
        private void InitializeTerminalInfo()
        {
            AppendLog("InitializeTerminalInfo");

            TerminalInfo = new TerminalInfo();

            ManagementClass osClass = new ManagementClass("Win32_OperatingSystem");

            foreach (ManagementObject obj in osClass.GetInstances())
            {
                TerminalInfo.OsName         = obj["Caption"].ToString();                                                // OS名称
                TerminalInfo.OsVersion      = obj["Version"].ToString();                                                // OS版本
                TerminalInfo.OsType         = obj["OSArchitecture"].ToString();                                         // OS架构
                TerminalInfo.LastBootUpTime = StringToDateTime(obj["LastBootUpTime"].ToString());                       // OS最后启动时间
                TerminalInfo.InstallDate    = StringToDateTime(obj["InstallDate"].ToString());                          // OS安装时间
                TerminalInfo.ProductKey     = obj["SerialNumber"].ToString();                                           // OS序列号
                TerminalInfo.VisibleMemory  = MemoryToString(Convert.ToInt64(obj["TotalVisibleMemorySize"]), true);     // 可见内存
            }

            Int64           memorySize  = 0;
            Int32           memeryCount = 0;
            ManagementClass memoryClass = new ManagementClass("Win32_PhysicalMemory");

            foreach (ManagementObject obj in memoryClass.GetInstances())
            {
                memorySize += Convert.ToInt64(obj["Capacity"]);
                memeryCount++;
            }
            TerminalInfo.TotalMemory = MemoryToString(Convert.ToInt64(memorySize), false);                              // 总内存
            TerminalInfo.MemoryCount = memeryCount;                                                                     // 内存条数量

            ManagementClass processClass = new ManagementClass("Win32_Processor");

            foreach (ManagementObject obj in processClass.GetInstances())
            {
                TerminalInfo.ProcessorName  = obj["Name"].ToString();                                                   // CPU名称
                TerminalInfo.ProcessorId    = obj["ProcessorId"].ToString();                                            // CPU ID
                TerminalInfo.ProcessorCount = Int32.Parse(obj["NumberOfLogicalProcessors"].ToString());                 // CPU数量
            }

            DriveInfo[] driveInfos  = DriveInfo.GetDrives();
            Int64       diskSize    = 0;
            Int32       driverCount = 0;

            TerminalInfo.DriveCount = driveInfos.Length;
            foreach (DriveInfo drive in driveInfos)
            {
                if (drive.DriveType == DriveType.Fixed)
                {
                    diskSize += drive.TotalSize;
                    driverCount++;
                }
            }
            TerminalInfo.DiskSize   = MemoryToString(diskSize, false);                                                  // 磁盘容量
            TerminalInfo.DriveCount = driverCount;                                                                      // 分驱数量

            IPAddress[] ips = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
            TerminalInfo.Ipv4 = "";
            TerminalInfo.Ipv6 = "";
            foreach (IPAddress ip in ips)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    TerminalInfo.Ipv4 = ip.ToString();                                                                  // IPv4
                }
                else if (!ip.IsIPv6LinkLocal && !ip.IsIPv6Multicast && !ip.IsIPv6SiteLocal /* && !ip.IsIPv6Teredo*/)
                {
                    TerminalInfo.Ipv6 = ip.ToString();                                                                  // IPv6
                }
            }

            NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
            TerminalInfo.Mac = "";
            foreach (NetworkInterface ni in nis)
            {
                if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    String temp = ni.GetPhysicalAddress().ToString();
                    String mac  = temp.Substring(0, 2);
                    for (int i = 0; i < 5; i++)
                    {
                        mac += "-" + temp.Substring(i * 2 + 2, 2);
                    }
                    TerminalInfo.Mac = mac;                                                                             // MAC
                }
            }
        }
Example #2
0
 public StaticHardwareMonitor()
 {
     Info             = new TerminalInfo();
     xml              = new XElement("TerminalInfo");
     needRefreshedXML = false;
 }