I asked a somewhat related question but I want it to make it more concrete and 'programming' oriented, so here it goes:
Does any body know, if there is a .NET, JAVA or any other Framework, library, .jar file or what ever: to access S.M.A.R.T. Statistics?
Thanks!
asked Sep 27, 2008 at 16:40
ramayac
5,22310 gold badges53 silver badges59 bronze badges
-
You should maybe reword your question, judging from the accepted answer you want this to work for windows only.Jan Jungnickel– Jan Jungnickel2009年07月19日 11:01:04 +00:00Commented Jul 19, 2009 at 11:01
1 Answer 1
You can get SMART statistics from .Net via the System.Management and WMI class "MSStorageDriver_ATAPISmartData".
Here is a short example that I created for you. Start a new console project and add a reference to the System.Management assembly, then paste this into Program.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace GetSMART
{
class Program
{
static void Main(string[] args)
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
"root\\WMI",
"SELECT * FROM MSStorageDriver_ATAPISmartData"
);
foreach (ManagementObject item in searcher.Get())
{
foreach( PropertyData prop in item.Properties )
{
Console.WriteLine("{0} = {1}",
prop.Name, prop.Value);
}
}
Console.ReadLine();
}
}
}
answered Sep 27, 2008 at 17:41
Wayne Bloss
5,5907 gold badges55 silver badges87 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
ramayac
Beautiful, thank you!... too bad it isn't Java hehe.
Wayne Bloss
No problem. FYI, I just searched for Java WMI and there are a lot of articles out there.
lang-java