By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,142 Members | 1,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,142 IT Pros & Developers. It's quick & easy.

How to get the harddrive drive letter? (or how many drive in a computer)

P: n/a
how can i know how many drive in computer?

Thanks in advance
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you may use the Windows API method below:DWORD GetLogicalDriveStrings(
DWORD nBufferLength,
LPTSTR lpBuffer
);
"Jason Chan" <no@mail.com> 写入消息新闻
:eg*************@TK2MSFTNGP10.phx.gbl...
how can i know how many drive in computer?

Thanks in advance

Nov 16 '05 #2

P: n/a
You can use WMI

Here is an example:

/* CODE BEGIN */
using System;
using System.Management;

public class network
{
public static void Main()
{
SelectQuery query = new SelectQuery( "select name, FreeSpace from
win32_logicaldisk where drivetype=3" );
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach( ManagementObject mo in searcher.Get() )
{
Console.WriteLine( "Drive letter is: {0}", mo["name"] );
Console.WriteLine( "Drive's free space is: {0}", mo["FreeSpace"] );
}

// Here to stop app from closing
Console.WriteLine( "\n\nPress Return to exit." );
Console.Read();
}
}
/* CODE END */
I have an example app here for network drives.
http://www.publicjoe.f9.co.uk/csharp/snip/snip010.html
The page has links to relevant MSDN pages as well.

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html


"Jason Chan" <no@mail.com> wrote in message
news:eg*************@TK2MSFTNGP10.phx.gbl...
how can i know how many drive in computer?

Thanks in advance

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.