Von:
Here is a peice of code. The parameter to pass is the servername (hostname)
and will get you basic stat need for storage management. It is in C# and you
can easily convert it to VB.Net in minutes.
private void CalculateFreeUsed(string srvname)
{
try
{
// Connection credentials to the remote computer -
// not needed if the logged in account has access
ConnectionOptions oConn = new ConnectionOptions();
// oConn.Username = "JohnDoe";
// oConn.Password = "JohnsPass";
string strNameSpace = @"\\";
if (srvname != "")
strNameSpace += srvname;
else
strNameSpace += ".";
strNameSpace += @"\root\cimv2";
System.Management.ManagementScope oMs = new
System.Management.ManagementScope(strNameSpace, oConn);
//get Fixed disk stats
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select FreeSpace,Size,Name from
Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
//Get the results
ManagementObjectCollection oReturnCollection = oSearcher.Get();
//loop through found drives and write out info
foreach( ManagementObject oReturn in oReturnCollection )
{
// Disk name
//Console.WriteLine("Name : " + oReturn["Name"].ToString());
// Free Space in bytes
strFreespace = oReturn["FreeSpace"].ToString();
D_Freespace = D_Freespace + System.Convert.ToDouble(strFreespace);
// Size in bytes
strTotalspace = oReturn["Size"].ToString();
D_Totalspace = D_Totalspace + System.Convert.ToDouble(strTotalspace);
}
}
catch
{
MessageBox.Show("Failed to obtain Server Information. The node you are
trying to scan can be a Filer or a node which you don't have administrative
priviledges. Please use the UNC convention to scan the shared folder in the
server","Server Error",MessageBoxButtons.OK, MessageBoxIcon.Error) ;
}
}
Hope this helps
Yonas