Export (0) Print
Expand All

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)

'Declaration
Public Shared Function GetLogicalDrives As String()

Return Value

Type: 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.

' 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:\ 
'

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft