Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
Environment Class
 GetLogicalDrives Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Environment..::.GetLogicalDrives Method

Returns an array of string containing the names of the logical drives on the current computer.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Shared Function GetLogicalDrives As String()
Visual Basic (Usage)
Dim returnValue As String()

returnValue = Environment.GetLogicalDrives()
C#
public static string[] GetLogicalDrives()
Visual C++
public:
static array<String^>^ GetLogicalDrives()
JScript
public static function GetLogicalDrives() : String[]

Return Value

Type: array<System..::.String>[]()[]
An array of strings where each element contains the name of a logical drive. For example, if the computer's hard drive is the first logical drive, the first element returned is "C:\".
ExceptionCondition
IOException

An I/O error occurs.

SecurityException

The caller does not have the required permissions.

The following example shows how to display the logical drives of the current computer using the GetLogicalDrives method.

Visual Basic
' Sample for the Environment.GetLogicalDrives method
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Dim drives As [String]() = Environment.GetLogicalDrives()
      Console.WriteLine("GetLogicalDrives: {0}", [String].Join(", ", drives))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'GetLogicalDrives: A:\, C:\, D:\
'
C#
// Sample for the Environment.GetLogicalDrives method
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    String[] drives = Environment.GetLogicalDrives();
    Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
    }
}
/*
This example produces the following results:

GetLogicalDrives: A:\, C:\, D:\
*/
Visual C++
// Sample for the Environment::GetLogicalDrives method
using namespace System;
int main()
{
   Console::WriteLine();
   array<String^>^drives = Environment::GetLogicalDrives();
   Console::WriteLine( "GetLogicalDrives: {0}", String::Join( ", ", drives ) );
}

/*
This example produces the following results:

GetLogicalDrives: A:\, C:\, D:\
*/

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker