472,958 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

No "AvailableSpace" property for Win32_LogicalDisk

I'm trying to display the available space on a disk drive. This could
be tricky if the user choose a drive on which they are limited to a
quota. The "FreeSpace" property returns the total number of bytes on
the disk, which could be significantly larger than the space actually
available to the user.

I found documentation referring to VB scripting, which provided an
"AvailableSpace" property, in addition to the "FreeSpace" property.
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/3d6a9eee11db3e6f/1417285711e11c94?lnk=st&q=%22AvailableSpace%22&rnu m=2#1417285711e11c94">Google
** sorry for this long URL, couldn't figure out how to make it a link

Is there an analog to this in C# / .NET WMI?

Here's some sample code in case I haven't been clear about what I'm
doing:

private String GetFreeSpace(String inVolume)
{
ManagementObject disk = new
ManagementObject("win32_logicaldisk.deviceid=\"" +
inVolume + "\"");
disk.Get();
int megabytes = (int)((Convert.ToInt64(disk["FreeSpace"]) /
1024) / 1024);

// does something like this property exist?
//int megabytes = (int)((Convert.ToInt64(disk["FreeSpace"])
/ 1024) / 1024);

return megabytes.ToString();
}

Jan 20 '07 #1
3 6027
<cm*******@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
I'm trying to display the available space on a disk drive. This could
be tricky if the user choose a drive on which they are limited to a
quota. The "FreeSpace" property returns the total number of bytes on
the disk, which could be significantly larger than the space actually
available to the user.

I found documentation referring to VB scripting, which provided an
"AvailableSpace" property, in addition to the "FreeSpace" property.
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/3d6a9eee11db3e6f/1417285711e11c94?lnk=st&q=%22AvailableSpace%22&rnu m=2#1417285711e11c94">Google
** sorry for this long URL, couldn't figure out how to make it a link

Is there an analog to this in C# / .NET WMI?

Here's some sample code in case I haven't been clear about what I'm
doing:

private String GetFreeSpace(String inVolume)
{
ManagementObject disk = new
ManagementObject("win32_logicaldisk.deviceid=\"" +
inVolume + "\"");
disk.Get();
int megabytes = (int)((Convert.ToInt64(disk["FreeSpace"]) /
1024) / 1024);

// does something like this property exist?
//int megabytes = (int)((Convert.ToInt64(disk["FreeSpace"])
/ 1024) / 1024);

return megabytes.ToString();
}


On W2K3 or higher you can use the win32_VolumeUserQuota to get at the user quota status.

Here is something that might get you started...
...
// Account "administrators" on "BOBSMACHINE"
string userAccount = "Win32_UserAccount.Domain=\"BOBSMACHINE\",Name=\"a dministrators\"";
ManagementObject uAcc = new ManagementObject(userAccount);
// Diskvolume C:\
string quotaVolume = @"Win32_QuotaSetting.VolumePath=" + "\"" + @"c:\\" +"\"";
RelatedObjectQuery relatedQuery = new RelatedObjectQuery
("associators of {" + quotaVolume +"}");
relatedQuery.RelatedClass = "win32_Volume";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(relatedQuery);
foreach(ManagementObject vol in searcher.Get())
{
string volPath = vol.Path.ToString().Replace("\\", "\\\\");
volPath = VolumeS.Replace("\"", "\\\"");
string classPath =
String.Format("Win32_VolumeUserQuota.Account=\"{0} \",Volume=\"{1}\"",
uAcc .Path.ToString().Replace("\"", "\\\""), VolumeS);
ManagementObject vuq = new ManagementObject(classPath);
Console.WriteLine("Account {0}, has {1} bytes used from {2} {3} {4}",
vuq["Account"].ToString(),
vuq["DiskSpaceUsed"].ToString(),
vuq["Limit"].ToString(),
vuq["Volume"].ToString(),
vuq["WarningLimit"].ToString());
}
}

Jan 20 '07 #2
Willy -

Thanks for the sample code - very helpful. It makes sense that this
kind of data would be related to the specific user, since that's how
quotas are set up.

Cheri

Willy Denoyette [MVP] wrote:
<cm*******@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
I'm trying to display the available space on a disk drive. This could
be tricky if the user choose a drive on which they are limited to a
quota. The "FreeSpace" property returns the total number of bytes on
the disk, which could be significantly larger than the space actually
available to the user.

I found documentation referring to VB scripting, which provided an
"AvailableSpace" property, in addition to the "FreeSpace" property.
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/3d6a9eee11db3e6f/1417285711e11c94?lnk=st&q=%22AvailableSpace%22&rnu m=2#1417285711e11c94">Google
** sorry for this long URL, couldn't figure out how to make it a link

Is there an analog to this in C# / .NET WMI?

Here's some sample code in case I haven't been clear about what I'm
doing:

private String GetFreeSpace(String inVolume)
{
ManagementObject disk = new
ManagementObject("win32_logicaldisk.deviceid=\"" +
inVolume + "\"");
disk.Get();
int megabytes = (int)((Convert.ToInt64(disk["FreeSpace"]) /
1024) / 1024);

// does something like this property exist?
//int megabytes = (int)((Convert.ToInt64(disk["FreeSpace"])
/ 1024) / 1024);

return megabytes.ToString();
}

On W2K3 or higher you can use the win32_VolumeUserQuota to get at the user quota status.

Here is something that might get you started...
...
// Account "administrators" on "BOBSMACHINE"
string userAccount = "Win32_UserAccount.Domain=\"BOBSMACHINE\",Name=\"a dministrators\"";
ManagementObject uAcc = new ManagementObject(userAccount);
// Diskvolume C:\
string quotaVolume = @"Win32_QuotaSetting.VolumePath=" + "\"" + @"c:\\" +"\"";
RelatedObjectQuery relatedQuery = new RelatedObjectQuery
("associators of {" + quotaVolume +"}");
relatedQuery.RelatedClass = "win32_Volume";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(relatedQuery);
foreach(ManagementObject vol in searcher.Get())
{
string volPath = vol.Path.ToString().Replace("\\", "\\\\");
volPath = VolumeS.Replace("\"", "\\\"");
string classPath =
String.Format("Win32_VolumeUserQuota.Account=\"{0} \",Volume=\"{1}\"",
uAcc .Path.ToString().Replace("\"", "\\\""), VolumeS);
ManagementObject vuq = new ManagementObject(classPath);
Console.WriteLine("Account {0}, has {1} bytes used from {2} {3} {4}",
vuq["Account"].ToString(),
vuq["DiskSpaceUsed"].ToString(),
vuq["Limit"].ToString(),
vuq["Volume"].ToString(),
vuq["WarningLimit"].ToString());
}
}
Jan 22 '07 #3
<cm*******@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
Willy -

Thanks for the sample code - very helpful. It makes sense that this
kind of data would be related to the specific user, since that's how
quotas are set up.
Specific users or user groups. Users quota's are only possible on Server OSses (W2K/W2K3),
on Client OSses you can only set quotas per group.

Willy.
Jan 22 '07 #4

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

Similar topics

3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
2
by: Edward Diener | last post by:
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? Finally how is one notified in...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
27
by: sklett | last post by:
I just found myself doing something I haven't before: <code> public uint Duration { get { uint duration = 0; foreach(Thing t in m_things) { duration += t.Duration;
15
by: Lauren Wilson | last post by:
Owning your ideas: An essential tool for freedom By Daniel Son Thinking about going into business? Have an idea that you think will change the world? What if you were told that there was no way...
0
by: Memfis | last post by:
While I was looking through the group's archives I came across a discussion on doing properties (as known from Delphi/C#/etc) in C++. It inspired me to do some experimenting. Here's what I came up...
0
ADezii
by: ADezii | last post by:
The motivation for this Tip was a question asked by one of our Resident Experts, FishVal. The question was: How to Declare Default Method/Property in a Class Module? My response to the question was...
1
by: cday119 | last post by:
I have a Class with about 10 properties. All properties return right except for one. It is real annoying and I can't see why its not working. Maybe someone else can see something. It is the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.