Solved

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

Posted on 2011-03-21
9
636 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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

19 Experts available now in Live!

Get 1:1 Help Now