public string GetHardSerial() { ManagementObjectSearcher Finder = new ManagementObjectSearcher("Select * from Win32_OperatingSystem"); string Name = ""; string SerialNumber = ""; foreach (ManagementObject OS in Finder.Get()) Name = OS["Name"].ToString(); //Name = "Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1" int ind = Name.IndexOf("Harddisk") + 8; int HardIndex = Convert.ToInt16(Name.Substring(ind, 1)); Finder = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE Index=" + HardIndex); foreach (ManagementObject HardDisks in Finder.Get()) foreach (ManagementObject HardDisk in HardDisks.GetRelated("Win32_PhysicalMedia")) SerialNumber = HardDisk["SerialNumber"].ToString(); // TextBox1.Text = Convert.ToString(Name); // TextBox2.Text = Convert.ToString(SerialNumber); return SerialNumber; }
string windir = Environment.GetEnvironmentVariable("windir"); //or systemroot Console.WriteLine("Windows OS is installed on: '{0}'", windir); //displays: Windows OS is installed on 'C:\Windows' //get drive info... DriveInfo drive = DriveInfo.GetDrives() .Where(d=>windir.Contains(d.Name)) .SingleOrDefault(); //further logic here....
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)