利用API函数GetVolumeInformation 取a:\的信息,根据返回值判断是否有软盘存在。
调用disk函数,若返回为真则有软盘,反之无软盘
Option Explicit
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As _
String, ByVal lpVolumeNameBuffer As _
String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As LongFunction disk() As Boolean
Dim Volume As String, SysName As String, drvname As String
Dim SerialNum As Long, SysFlags As Long, ComponentLength As Long, Res As Long
Volume = String(256, 0)
SysName = String(256, 0)
drvname = "a:\"
Res = GetVolumeInformation(drvname, Volume, 255, SerialNum, ComponentLength, SysFlags, SysName, 255)
If Res = 0 Then
disk = False
Else
disk = True
End If
End Function
调用disk函数,若返回为真则有软盘,反之无软盘
Option Explicit
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As _
String, ByVal lpVolumeNameBuffer As _
String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As LongFunction disk() As Boolean
Dim Volume As String, SysName As String, drvname As String
Dim SerialNum As Long, SysFlags As Long, ComponentLength As Long, Res As Long
Volume = String(256, 0)
SysName = String(256, 0)
drvname = "a:\"
Res = GetVolumeInformation(drvname, Volume, 255, SerialNum, ComponentLength, SysFlags, SysName, 255)
If Res = 0 Then
disk = False
Else
disk = True
End If
End Function
解决方案 »
- SQL语句问题(3表连查)
- 一个关于EXCEL中VBA代码的问题
- 调用api,As Any,出现错误“类型不匹配”
- 出鬼了;很简单的代码,执行可以;但不显示结果;!在线等;急啊
- 不知道大家格式化美观源代码用什么?(CodeSMART or SourceFormatX)
- 怎么提取指定文件的图标?
- 比较简单的问题?如何取得本机IP地址???
- 我的数据库连接问题,与众不同
- 怎样才可以提高VB的运行速度呢
- 请问各位老大!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 窗体上哪么多控件.怎樣判斷哪個獲得焦點?
- 简单的问题*********如何用最简便的方法从这样的字符串中获取文件名称??
用API GetDiskFreeSpace 判断。
如果磁盘总磁道数为0,就是没盘了。
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As LongDim i As Long
i = GetDiskFreeSpace("a:", a, b, c, d)
If d= 0 Then
MsgBox "no disk"
End If