Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-21
9
Medium Priority
?
652 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 400 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 400 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 1200 total points
ID: 35185835
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

609 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