473,807 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No "AvailableSpace " property for Win32_LogicalDi sk

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.c om/group/microsoft.publi c.scripting.vbs cript/browse_frm/thread/3d6a9eee11db3e6 f/1417285711e11c9 4?lnk=st&q=%22A vailableSpace%2 2&rnum=2#141728 5711e11c94">Goo gle
** 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(St ring inVolume)
{
ManagementObjec t disk = new
ManagementObjec t("win32_logica ldisk.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.ToStr ing();
}

Jan 20 '07 #1
3 6100
<cm*******@gmai l.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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.c om/group/microsoft.publi c.scripting.vbs cript/browse_frm/thread/3d6a9eee11db3e6 f/1417285711e11c9 4?lnk=st&q=%22A vailableSpace%2 2&rnum=2#141728 5711e11c94">Goo gle
** 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(St ring inVolume)
{
ManagementObjec t disk = new
ManagementObjec t("win32_logica ldisk.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.ToStr ing();
}


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

Here is something that might get you started...
...
// Account "administrators " on "BOBSMACHIN E"
string userAccount = "Win32_UserAcco unt.Domain=\"BO BSMACHINE\",Nam e=\"administrat ors\"";
ManagementObjec t uAcc = new ManagementObjec t(userAccount);
// Diskvolume C:\
string quotaVolume = @"Win32_QuotaSe tting.VolumePat h=" + "\"" + @"c:\\" +"\"";
RelatedObjectQu ery relatedQuery = new RelatedObjectQu ery
("associator s of {" + quotaVolume +"}");
relatedQuery.Re latedClass = "win32_Volu me";
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(relat edQuery);
foreach(Managem entObject vol in searcher.Get())
{
string volPath = vol.Path.ToStri ng().Replace("\ \", "\\\\");
volPath = VolumeS.Replace ("\"", "\\\"");
string classPath =
String.Format(" Win32_VolumeUse rQuota.Account= \"{0}\",Volume= \"{1}\"",
uAcc .Path.ToString( ).Replace("\"", "\\\""), VolumeS);
ManagementObjec t vuq = new ManagementObjec t(classPath);
Console.WriteLi ne("Account {0}, has {1} bytes used from {2} {3} {4}",
vuq["Account"].ToString(),
vuq["DiskSpaceU sed"].ToString(),
vuq["Limit"].ToString(),
vuq["Volume"].ToString(),
vuq["WarningLim it"].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*******@gmai l.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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.c om/group/microsoft.publi c.scripting.vbs cript/browse_frm/thread/3d6a9eee11db3e6 f/1417285711e11c9 4?lnk=st&q=%22A vailableSpace%2 2&rnum=2#141728 5711e11c94">Goo gle
** 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(St ring inVolume)
{
ManagementObjec t disk = new
ManagementObjec t("win32_logica ldisk.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.ToStr ing();
}

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

Here is something that might get you started...
...
// Account "administrators " on "BOBSMACHIN E"
string userAccount = "Win32_UserAcco unt.Domain=\"BO BSMACHINE\",Nam e=\"administrat ors\"";
ManagementObjec t uAcc = new ManagementObjec t(userAccount);
// Diskvolume C:\
string quotaVolume = @"Win32_QuotaSe tting.VolumePat h=" + "\"" + @"c:\\" +"\"";
RelatedObjectQu ery relatedQuery = new RelatedObjectQu ery
("associator s of {" + quotaVolume +"}");
relatedQuery.Re latedClass = "win32_Volu me";
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(relat edQuery);
foreach(Managem entObject vol in searcher.Get())
{
string volPath = vol.Path.ToStri ng().Replace("\ \", "\\\\");
volPath = VolumeS.Replace ("\"", "\\\"");
string classPath =
String.Format(" Win32_VolumeUse rQuota.Account= \"{0}\",Volume= \"{1}\"",
uAcc .Path.ToString( ).Replace("\"", "\\\""), VolumeS);
ManagementObjec t vuq = new ManagementObjec t(classPath);
Console.WriteLi ne("Account {0}, has {1} bytes used from {2} {3} {4}",
vuq["Account"].ToString(),
vuq["DiskSpaceU sed"].ToString(),
vuq["Limit"].ToString(),
vuq["Volume"].ToString(),
vuq["WarningLim it"].ToString());
}
}
Jan 22 '07 #3
<cm*******@gmai l.comwrote in message
news:11******** **************@ 51g2000cwl.goog legroups.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
2501
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 the properties is a follows (irrelevant code omitted):
2
1763
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 a component when another component is destroyed ? I have a managed component called P. Let us say that C is another managed component. If on P I have: __property C * get_CComp(); __property void set_CComp(C *);
0
5570
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 is used to view the state of the running jobs and schedule new jobs. The control also runs in the context of Internet Explorer (we do this so the administrators of the jobs can always receive the latest control). The property grid is used to...
3
6763
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 following default properties: Height = 32px, Width = 144px. I declare the Width property in my control as... \\\
15
1929
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 two? (1)
27
5652
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
2055
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 you could prevent someone from stealing your idea and exploiting it to make a profit? What incentive would there be for you to be innovative, creative and ambitious if you couldn’t be sure that your ideas would be protected? Enter intellectual...
0
1988
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 with. First we have an interface defining how a property can be used (read and written - for simplicity, I ignored read-only and write-only variants). template<typename Tclass Property { public:
0
25601
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 inadequate to say the least, but I was determined to come up with the correct answer, especially since my primary background is Visual Basic, and I knew that there was an answer. Well, I did come up with an answer and I decided to incorporate it into...
1
1357
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 NumberLines property. I can set it to 4 but when it returns it is set to 1 Public Class Profile Private ProfileFileName As String Private ProfileDescription As String Private ProfileVersion As Integer Private...
0
10626
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10112
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6879
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3011
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.