コード例 #1
0
ファイル: HardDrive.cs プロジェクト: JGDIFF/VAPOR-Client
        public static String GetHardDriveInfo()
        {
            ArrayList hdCollection            = new ArrayList();
            ManagementObjectSearcher searcher = new
                                                ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

            foreach (ManagementObject wmi_HD in searcher.Get())
            {
                HardDrive hd = new HardDrive();
                hdCollection.Add(hd);
            }

            searcher = new
                       ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

            int i = 0;

            foreach (ManagementObject wmi_HD in searcher.Get())
            {
                // get the hard drive from collection
                // using index
                HardDrive hd = (HardDrive)hdCollection[i];

                // get the hardware serial no.
                if (wmi_HD["SerialNumber"] == null)
                {
                    hd.SerialNo = "None";
                }
                else
                {
                    hd.SerialNo = wmi_HD["SerialNumber"].ToString();
                }

                ++i;
            }
            foreach (HardDrive hd in hdCollection)
            {
                return(hd.SerialNo.ToString());
            }
            return("null");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string Date1      = DateTime.UtcNow.ToString("dddd, dd MMMM yyyy UTC HH;mm;ss ");
            string pathString = @"C:\Program Files (x86)\VAPOR Client\Logs";
            string fileName   = Date1 + "logs.csv";

            Directory.CreateDirectory(pathString);
            pathString = System.IO.Path.Combine(pathString, fileName);



            // Get host name
            string strHostName     = Dns.GetHostName();
            string WinComputerName = System.Environment.MachineName.ToString();

            // Get PC Uptime from Uptime class.
            System.TimeSpan Uptime = Uptimes.GetUptime();

            // Get Public IP from PublicIP class.
            string publicIP = PublicIP.getPublicIP();


            foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                string Date   = DateTime.UtcNow.ToString("dddd, dd MMMM yyyy");
                string PCName = WinComputerName.ToLower();

                if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    foreach (UnicastIPAddressInformation ip in netInterface.GetIPProperties().UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            if (!System.IO.File.Exists(pathString))
                            {
                                Console.WriteLine("Creating file");
                                System.IO.FileStream fs = System.IO.File.Create(pathString);
                                fs.Close();
                                {
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(pathString))
                                    {
                                        file.WriteLine(Date + "," + ip.Address.ToString() + "," + netInterface.GetPhysicalAddress().ToString() + "," + WinComputerName + "," + strHostName + "," + HardDrive.GetHardDriveInfo().TrimStart() + "," + new ComputerInfo().OSFullName + "," + Uptime);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("File \"{0}\" already exists, appending file", fileName);
                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(pathString, true))
                                {
                                    file.WriteLine(Date + "," + ip.Address.ToString() + "," + netInterface.GetPhysicalAddress().ToString() + "," + WinComputerName + "," + strHostName + "," + HardDrive.GetHardDriveInfo().TrimStart() + "," + new ComputerInfo().OSFullName + "," + Uptime);
                                }
                            }
                        }
                    }
                }
            }
        }