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.

Windows Registry Size

Tagged with:
 

2 Responses to Get Windows Registry Size With WMI And C#

  1. w3n says:

    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”));

    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>