Get Windows Registry Size With WMI And C#
Windows Registry Size can be retrieved using WMI objects. This code snippet shows you how to get current size and maximum size for Windows registry.
ManagementObjectSearcher mgmtObjects = new ManagementObjectSearcher("Select * from Win32_Registry");foreach (var item in mgmtObjects.Get()){ Console.WriteLine(string.Format("Current Size: {0}MB", item["CurrentSize"])); Console.WriteLine(string.Format("Maximum Size: {0}MB", item["MaximumSize"]));}
The output.
![]()







Ok, it works, but, this is not the right way of doing this:
1. U are doing an ugly boxing when the collection type returned from mgmtObjects.Get() is a collection of ManagementObject. Not a nice idea since you are just retrieving two values.
2. By using a ManagementObjectSearcher you are performing a search, this is an unnecesary performance lack… I suggest you to use something like:
ManagementClass __mgmtObjects = new ManagementClass(“Win32_Registry”);
foreach (ManagementObject __mngObj in __mgmtObjects.GetInstances())
{
Console.WriteLine(“Maximun Size {0}MB Current Size :{1}MB”, __mngObj.GetPropertyValue(“MaximumSize”), __mngObj.GetPropertyValue(“CurrentSize”));
}
Thanks w3n