在本文中通过GetLogicalDriveStrings函数,获取到“逻辑磁盘驱动根路径字串”
然后我们再把返回的缓冲区中的值进行处理、
函数示意:
GetLogicalDriveStrings 取逻辑磁盘驱动根路径字串
成功返回“逻辑磁盘驱动根路径字串”大小、否则返回缺省值0
nBufferLength 欲接收缓冲区尺寸
lpBuffer 欲接收缓冲区指针
示例代码:
Imports System.Runtime.InteropServices Imports System.Text.RegularExpressions Module MainModule Public Declare Function GetLogicalDriveStrings Lib "kernel32.dll" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Integer,ByVal lpBuffer As String) As Integer Sub Main() Console.Title = "取磁盘驱动器列表" Dim len As Integer = GetLogicalDriveStrings(0,Nothing) If (len <= 0) Then Throw New Exception("Unable to get buffer length.") End If Dim buffer As String = Space(len) If (GetLogicalDriveStrings(len,buffer) <= 0) Then Throw New Exception("Unable to get the list of disks.") End If Dim matchs = Regex.Matches(buffer,"[A-Z|a-z]+\:\\") For Each match As Match In matchs Console.WriteLine(match.Value) Next Console.ReadKey(False) End Sub End Module原文链接:https://www.f2er.com/vb/257214.html