473,520 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to measure hard disk capacity?

How to measure hard disk capacity?

Nov 16 '05 #1
2 12339
AlirezaH,

I would perform a WMI query for the instance of Win32_PhysicalMedia that
represents the actual drive and then check the Capacity property on it. You
can use the classes in the System.Management namespace to access this data.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"AlirezaH" <al******@abcgrp.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
How to measure hard disk capacity?

Nov 16 '05 #2
AlirezaH wrote:
How to measure hard disk capacity?


This will do a little more:

using System;
using System.Management;

namespace sample {

/// <summary>
/// Displays disk space information for all connected hard drives.
/// </summary>
class freeSpace {

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main() {
string query = "select name, FreeSpace, Size from win32_logicaldisk
where drivetype=3";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach(ManagementObject manobj in searcher.Get()) {
double freespace2 = double.Parse(manobj["FreeSpace"].ToString());
double disksize2 = double.Parse(manobj["Size"].ToString());
double pctfree2 = freespace2 / disksize2;
int lengthdiff = disksize2.ToString("N0").Length -
freespace2.ToString("N0").Length;

Console.WriteLine("For drive {0}", manobj["name"]);
Console.WriteLine("\tDisk size: " + disksize2.ToString("N0") + "
bytes");

/// <summary>
/// Format the free space line so the number lines up
/// right-justified with the disk size number
/// when using a fixed-width font.
/// </summary>
switch (lengthdiff) {
case 0:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0") +
" bytes");
break;
case 1:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0") +
" bytes");
break;
case 2:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0")
+ " bytes");
break;
case 3:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0")
+ " bytes");
break;
default :
Console.WriteLine("\tFree space: " + freespace2.ToString("N0") +
" bytes");
break;
}
Console.WriteLine();

Console.WriteLine("\tPercent free: " + pctfree2.ToString("P"));
Console.WriteLine();
Console.WriteLine();
}
}
}
}
--
Take care,
Ken
(to reply directly, remove the cool car. <sigh>)
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4465
by: Paul | last post by:
Hi: I am totally new in Sun Solaris. I am not sure someone would like to tell me how to rellocate Sun Solaris disk space where oracle installed? I installed Oracle 8i in Sun Solaris and set Oracle main table space called TABLES in unix disk space /dpp/live01. From the following, it's quite easy to see that the disk space of /dpp/live01...
5
1915
by: Ben Jeurissen | last post by:
Hello, I have to deal with the following issue in C++: Two threads are started from the main thread, both capturing images from a different firewire camera. Both threads take shots of 460800 bytes at a rate of 30 frames per second. This works fine, without frame loss, and I can display the two framestreams on screen. Now I would like...
2
3732
by: Joe | last post by:
Hi Guys, Is it possible to create a disk management system using .NET entirely. What I mean by the above is having an application possibly a .NET windows service monitoring the disk, creating and adding users and giving them access to store a limited amount of data. The only thing which does this in my knowledge is the FileSystemWatcher...
3
9982
by: abeer el ashker | last post by:
how can i get serial numper of hard disk using api
13
1838
by: Shane Wright | last post by:
Hi, I've been trying to spec a new server for my company's database for a few weeks and one of the biggest problems I've had is trying to find meaningful performance information about how PostgreSQL will perfom under various disk configurations. But, we have now taken the plunge and I'm in a position to do some benchmarking to actually...
6
30689
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk serial number would do fine, but on Googling it seems that some of the sample code will now laways work on W2K, and not without administrator...
3
6444
by: ary | last post by:
I try to create a weblog host site! in this case i can't use cache for every page because that cause to be my Server ram full of caching page. but if I can save cache in hard disk my problem solved? can help me? thanks.
2
3133
by: =?Utf-8?B?R2VvcmR5?= | last post by:
Hello everyone, I would really appreciate if someone helped me in this matter cause I am going to lose my mind... I am using a Sony Vaio Laptop with Windows XP professional (512MB Ram, 1,7 GHz CPU clock, 50GB Hard disk) and for the past 10 days i have noticed that my hard disk space is decreasing dramatically without installing or running any...
10
22584
by: kevinliu23 | last post by:
HI, I am new to Python and wanted to know how to check for the remaining disk space on my Windows machine using Python? I was thinking of using the command line "dir" and trying to extract the output from there. But I'm not sure how to extract command line strings using Python either. Anyway help would be appreciated. :)
0
7326
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7238
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7210
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3298
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
857
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
531
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.