Getting Volume serial number and other information

G

Guest

Hi group
I'm trying to implement a console application which work just lie "Dir"
instruction in MS-Dos prompt window so I need to display Volume Serial Number
and also the free space, how can I get Volume Serial Number and other related
informations and is there any function in .Net which will return the
available free space in a specified drive?
Regards,
 
G

Guest

Hi Ian
Thanx for your reply but could you please explain more or give an example in
C#
 
I

Ian Frawley

Taking no credit for this as I ripped it off: there are lots of examples on
the net

//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";

System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\MachineX", 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
Console.WriteLine("FreeSpace: " + oReturn["FreeSpace"].ToString());
// Size in bytes
Console.WriteLine("Size: " + oReturn["Size"].ToString());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top