Solved

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

Posted on 2011-03-21
9
635 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:jl66
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Expert Comment

by:systan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot for everyone's tips, with which I figured out the issue.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
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:…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now