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.
![]()
2 Responses to Get Windows Registry Size With WMI And C#
Leave a Reply Cancel reply
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML


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