How to get disk usage for any domain computer in C#

In VBasic there is very decent application to get trhe disk usage across the domain computers. Is there any applicaiton to get the disk usage in C#?
Who is Participating?
Nathan BoveConnect With a Mentor Software EngineerCommented:
Anything that is available in VB.NET is also available in C#.  Just reference the Visual Basic libraries in your C# project and you can call any of the appropriate functions.

So, in short, add a reference to Microsoft.VisualBasic in your C# project.
JoelDevConnect With a Mentor Commented:
nbove is correct.

Also, It isn't very clear what you are referring to, but I'm guessing you're referring to the "My" namespace available in VB.Net. The “My” namespace just contains nice, easy to find shortcuts to other methods, properties, etc. available elsewhere in the .Net framework.

For instance: if you are looking for the My.Computer.FileSystem calls, you should be able to find most of that functionality in the System.IO namespace.

Hope that helps.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

jl66Author Commented:
Thanks for everyone's tips.
systan: the 1st link seems fit me best. However I got errors with it.
It complains the following
foreach (ManagementObject mo in searcher.Get())

Error      2      Invalid token 'foreach' in class, struct, or interface member declaration

Can you test it to see if you have the same issue?
We have the same issue;
and I think this 3rd link work fine;

jl66Author Commented:
Thanks for response. 3 rd one worked. I need to get the disk usages for several network computers, so I will have to have that worked, I feel strange that the syntax is almost same in VB as VC#, but it worked in VB but not in VC#.
I hope you did the right usage.

What is your command usage in and also in c_sharp?, in getting the network drive usage.
jl66Author Commented:
The working VB code is

Set oLocator = CreateObject("WbemScripting.SWbemLocator")
Set oService = oLocator.ConnectServer (sServer,"root\cimv2")
sQuery="Select DriveType,DeviceID,Size,FreeSpace from win32_logicaldisk where DriveType='3'"
Set oRef=oService.ExecQuery(sQuery,,48)
For Each drive In oRef

Who can translate to VC#, which still works?
jl66Author Commented:
Thanks a lot for everyone's tips, with which I figured out the issue.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.