Solved

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

Posted on 2011-03-21
9
642 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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