计算机语言硬盘序列号,硬盘序列号 | 码农俱乐部 - Golang中国 - Go语言中文社区...

'''尝试运行此代码

Const CheckDrive_NotRem = 0

Const CheckDrive_RemAndFound = 1

Const CheckDrive_RemAndNotFound = 2

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

'InPut: the letter of the drive to check it or the string "all" to check for all drives

Public Function CheckNow(strDrive As String)

Dim strSave As String

Dim strDriveName As String

Dim Res, keer, DiskFound

'Create a buffer to store all the drives

strSave = String(255, Chr$(0))

'Get all the drives

ret& = GetLogicalDriveStrings(255, strSave)

'Extract the drives from the buffer

For keer = 1 To 100

If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For

strDriveName = Left$(strSave, InStr(1, strSave, Chr$(0)) - 1)

'Check the drive for type and diskettes

If strDrive = "all" Then

Res = CheckDrive(strDriveName)

If Res = CheckDrive_RemAndNotFound Then

MsgBox "No Disk in drive: " & strDriveName

ElseIf Res = CheckDrive_RemAndFound Then

MsgBox "There is a Disk in drive: " & strDriveName

End If

ElseIf (strDrive + ":\") = strDriveName Then

Res = CheckDrive(strDriveName)

If Res = CheckDrive_RemAndNotFound Then

MsgBox "No Disk in drive: " & strDriveName

ElseIf Res = CheckDrive_RemAndFound Then

MsgBox "There is a Disk in drive: " & strDriveName

ElseIf Res = CheckDrive_NotRem Then

MsgBox "This isn't a removal or CD-Rom drive"

End If

DiskFound = True

Exit For

End If

strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))

Next keer

'Check whether there is a drive with the letter the user entered

If (Not DiskFound) And (strDrive <> "all") Then MsgBox "No drive with this letter found!"

End Function

''''''''''''''''''''''''

'Task:

'1) Check whether the drive is removal or CD-Rom or not

'2) Check if there is a disk in the drive

'The idea depends on changing the directory to the drive

'path then check: if an error happens that means the program

'can't change the directory to the path of the disk.

'Consequently, there is no disk, and the function returns

'

'OutPut of CheckDrive:

' 0 = The drive isn't removal or CD-Rom

' 1 = There is a Disk in the drive

' 2 = There is no Disk in the drive

''''''''''''''''''''''''

Function CheckDrive(strDrive As String) As Integer

On Error GoTo errhandler

Select Case GetDriveType(strDrive)

Case 2 ' Removal

ChDir strDrive

CheckDrive = CheckDrive_RemAndFound ' The drive is removal and there is a disk

Exit Function

Case 5 ' CD-Rom drive

ChDir strDrive

CheckDrive = CheckDrive_RemAndFound ' The drive is CD-Rom and there is a disk

Exit Function

End Select

Exit Function

errhandler:

'there isn't a Disk in the drive

If Err.Number = 75 Then CheckDrive = 2 'Path/access error

End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值