Solved

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

Posted on 2011-03-21
9
639 Views
Last Modified: 2013-12-17
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#?
0
Comment
Question by:jl66
9 Comments
 
LVL 7

Assisted Solution

by:nbove
nbove earned 100 total points
ID: 35185194
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.
0
 

Assisted Solution

by:JoelDev
JoelDev earned 100 total points
ID: 35185623
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.
0
 
LVL 14

Accepted Solution

by:
systan earned 300 total points
ID: 35185835
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jl66
ID: 35186810
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?
0
 
LVL 14

Expert Comment

by:systan
ID: 35192973
We have the same issue;
and I think this 3rd link work fine;
http://www.scriptslibrary.net/c-sharp/99-get-drive-free-space-in-c

usage;
MessageBox.Show(GetDriveInfo("C:/"));
or
MessageBox.Show(GetDriveInfo("\\\yourSERVER\\\C$"));
0
 

Author Comment

by:jl66
ID: 35194178
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#.
0
 
LVL 14

Expert Comment

by:systan
ID: 35200615
I hope you did the right usage.
usage;
MessageBox.Show(GetDriveInfo("C:/"));

What is your command usage in vb.net? and also in c_sharp?, in getting the network drive usage.
0
 

Author Comment

by:jl66
ID: 35203009
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
  PerFree=FormatPercent(drive.FreeSpace/drive.Size,2)
  Size=FormatNumber(drive.Size/1048576,2)
  Free=FormatNumber(drive.FreeSpace/1048576,2)
Next

Who can translate to VC#, which still works?
0
 

Author Closing Comment

by:jl66
ID: 35204866
Thanks a lot for everyone's tips, with which I figured out the issue.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Issue with SSIS module 26 134
Import MySQL data into MS Access using VB.Net interface 5 47
Name Space error VS2015 1 35
IDE for Python 5 62
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question