473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

disk size, space with UNC

If I have a drive letter I can get the the drive info from WMI like this

string ltrDr=theSharePath.Substring(0,2); // must be in form of "E:
string wackyQuery =string.Format("Win32_LogicalDisk.DeviceID=\"{0}\" ",ltrDr)
ManagementObject DIdisk =new ManagementObject(wackyQuery)
DIdisk.Get()
qcShareSize= Convert.ToDouble(DIdisk["FreeSpace"])/1000000000; // in GigaByte

but if I just have the UNC what then ? What does WMI expect ??? I have not found any examples to map to drive ltr directly or simply use the UNC path.

Thanks Andrew:
Nov 16 '05 #1
4 10638
andrew,

If you have a UNC name, then you can not use the Win32_LogicalDisk
class. The reason for this is that this class corresponds to mapped drives
on the system.

If you want to get the disk free space of a network share, you will have
to call the GetDiskFreeSpace API through the P/Invoke layer.

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

"andrewcw" <an******@acw.com> wrote in message
news:D4**********************************@microsof t.com...
If I have a drive letter I can get the the drive info from WMI like this:

string ltrDr=theSharePath.Substring(0,2); // must be in form of "E:"
string wackyQuery =string.Format("Win32_LogicalDisk.DeviceID=\"{0}\" ",ltrDr); ManagementObject DIdisk =new ManagementObject(wackyQuery);
DIdisk.Get();
qcShareSize= Convert.ToDouble(DIdisk["FreeSpace"])/1000000000; // in GigaBytes
but if I just have the UNC what then ? What does WMI expect ??? I have not found any examples to map to drive ltr directly or simply use the UNC
path.
Thanks Andrew:

Nov 16 '05 #2
Thanks - I was trying to stay as much as possible within managed code. While waiting I put this code together - although it is not as direct ...it does get me the drive ltr & then I can use WMI for size. Seems an odd oversight in the class to not have such a function..

public string getDrvLtrFromUNC(string UNCPath
{ // get all the named drives then see whose ProviderNam
// matches the UNCPath, then return that drive letter ( form of "e: " - 2 chars
// empty string would be an unmapped or invalid drive path
string retVal=""
string thisDescrip=""
string thisUNCroot=""
string ltrDr=""
string wackyQuery=""
string [] logDrives=Directory.GetLogicalDrives()

for (int i = 0; i<logDrives.GetLength(0);i++

ltrDr=logDrives[i].Substring(0,2)
wackyQuery =string.Format("Win32_LogicalDisk.DeviceID=\"{0}\" ",ltrDr)
ManagementObject moDrive =new ManagementObject(wackyQuery)
thisDescrip= moDrive.Properties["Description"].Value.ToString()
if (thisDescrip.IndexOf("Network")>-1
{
thisUNCroot = moDrive.Properties["ProviderName"].Value.ToString()
if (thisUNCroot.ToLower().IndexOf(UNCPath.ToLower())>-1

retVal = ltrDr
break

} // end of a network driv

} // end of for loo

return retVal
}
Nov 16 '05 #3
Andrew,

It's not an oversight, it's the design of the class. A logical drive
and a network share are two separate things which sometimes are the same (if
that makes sense).

If you want to get this information in a consistent manner, then use the
GetDiskFreeSpace API call, or some other API which allows both logical
drives and UNC names.

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

"andrewcw" <an******@acw.com> wrote in message
news:E4**********************************@microsof t.com...
Thanks - I was trying to stay as much as possible within managed code. While waiting I put this code together - although it is not as direct ...it
does get me the drive ltr & then I can use WMI for size. Seems an odd
oversight in the class to not have such a function...
public string getDrvLtrFromUNC(string UNCPath)
{ // get all the named drives then see whose ProviderName
// matches the UNCPath, then return that drive letter ( form of "e: " - 2 chars) // empty string would be an unmapped or invalid drive path.
string retVal="";
string thisDescrip="";
string thisUNCroot="";
string ltrDr="";
string wackyQuery="";
string [] logDrives=Directory.GetLogicalDrives();

for (int i = 0; i<logDrives.GetLength(0);i++)
{
ltrDr=logDrives[i].Substring(0,2);
wackyQuery =string.Format("Win32_LogicalDisk.DeviceID=\"{0}\" ",ltrDr);
ManagementObject moDrive =new ManagementObject(wackyQuery);
thisDescrip= moDrive.Properties["Description"].Value.ToString();
if (thisDescrip.IndexOf("Network")>-1)
{
thisUNCroot = moDrive.Properties["ProviderName"].Value.ToString();
if (thisUNCroot.ToLower().IndexOf(UNCPath.ToLower())>-1)
{
retVal = ltrDr;
break;
}
} // end of a network drive

} // end of for loop

return retVal;
}

Nov 16 '05 #4
Thanks for reminding me of the differences. Hopefully this functionality will be pulled into the framework.
Nov 16 '05 #5

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

Similar topics

2
by: UnixSlaxer | last post by:
I am wondering, is the disk limit constraint in db2advis on a) The space of the recommended indexes and materialized views. b) The space of the recommended indexes and materialized views, as...
4
by: sandip | last post by:
Hi, Can anyone tell me how to calculate the ctual disk space needed for a table? The record length and number of records are known. A rough estimate of the disk space would suffice. Please...
2
by: AlirezaH | last post by:
How to measure hard disk capacity?
3
by: A P | last post by:
Hi, I am loosing disk space and wanting to install .Net Framework on my W2KSP4 Server. I only have 400MB available, is this enough for me to install .Net Framework? Me
1
by: Nils Rennebarth | last post by:
I have a table that is essentially a log where new entries are streaming in continually and from time to time I throw old entries away to keep the table from growing. I understand that in...
0
by: Paul | last post by:
Hi, I seem to be having an issue with a query's results being paged out to disk during runtime. I notice in processlist it saying "Copying to tmp table on disk". select col1, col2, count(ip)...
4
by: Konstantin Andreev | last post by:
Recently I was engaged in the database optimization for one big commercial application. During this business I was greatly astound by the fact that it's impossible in DB2 to get the accurate size of...
6
by: Christine | last post by:
erver Error in '/test' Application. -------------------------------------------------------------------------------- There is not enough space on the disk. Description: An unhandled exception...
34
by: Tom | last post by:
I'd greatly appreciate advice and code snippets on how to create a ram disk within a C/C++ program. I also need to be able to determine the free space. Thanks in advance for any help.
13
by: ragtag99 | last post by:
I posted this on comp.lang.asm.x86, alt.os.development, comp.arch, comp.lang.c++ Im working with windows xp professional, NTFS and programming with MASM, c++ (free compiler) or visual basic 6.0...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.