如何用DeviceIoControl检测一台机器上是否安装有软驱,最好有代码,很好着急

myckd 2001-10-04 05:48:04
期待
...全文
109 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
myckd 2001-10-04
  • 打赏
  • 举报
回复
gz
myckd 2001-10-04
  • 打赏
  • 举报
回复
这些方法都不管用,如果把软驱拔掉,在BIOS中不禁用软驱的话,照样能的到A为软驱
事实上并没有软驱
prog_st 2001-10-04
  • 打赏
  • 举报
回复
______________参考_________________

HOWTO: Use Visual Basic to Locate CD-ROM Drives

Q291575


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0

--------------------------------------------------------------------------------


SUMMARY
You can find the drive letter of any CD-ROM drive on a local computer by using the Win32 API from Visual Basic. This can be useful during scenarios such as program setup and querying a user for media.



MORE INFORMATION
You can use the GetDriveType API to determine the type of drive referenced by a drive letter. By combining this API with a list of the active drive letters on a computer, you can search for CD-ROM drives available on that computer. Note that the API does not distinguish between types of CD-ROM drives, so for example, a DVD drive is considered a CD-ROM drive.

The following code sample demonstrates how to search for local CD-ROM drives by using Visual Basic.

Sample Code
Start a new Visual Basic Standard EXE project. Form1 is created by default.


Add a new command button (Command1) to Form1.


Add the following code to Form1's code window:



Option Explicit

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

Const DRIVE_CDROM& = 5

Public Function GetDriveStrings() As String
' Wrapper for calling the GetLogicalDriveStrings api

Dim result As Long ' Result of our API calls
Dim strDrives As String ' String to pass to API call
Dim lenStrDrives As Long ' Length of the above string

' Call GetLogicalDriveStrings with a buffer size of zero to
' find out how large our stringbuffer needs to be
result = GetLogicalDriveStrings(0, strDrives)

strDrives = String(result, 0)
lenStrDrives = result

' Call again with our new buffer
result = GetLogicalDriveStrings(lenStrDrives, strDrives)

If result = 0 Then
' There was some error calling the API
' Pass back an empty string
' NOTE - TODO: Implement proper error handling here
GetDriveStrings = ""
Else
GetDriveStrings = strDrives
End If
End Function

Private Sub Command1_Click()
Dim strDrives As String

' Find out what drives we have on this machine
strDrives = GetDriveStrings()

If strDrives = "" Then
' No drives were found
MsgBox "No Drives were found!", vbCritical
Else
' Walk through the string and check the type of each drive
' displaying any cd-rom drives we find
Dim pos As Long
Dim drive As String
Dim drivetype As Long

pos = 1

Do While Not Mid$(strDrives, pos, 1) = Chr(0)
drive = Mid$(strDrives, pos, 3)
pos = pos + 4
drivetype = GetDriveType(drive)
If drivetype = DRIVE_CDROM Then
MsgBox "CD-ROM found at drive " & UCase(drive)
End If
Loop
End If
End Sub

Click Run or press the F5 key to run the project.


Result: Any CD-ROM drives on the computer are displayed by drive letter in a message box.



REFERENCES
For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

Q190000 HOWTO: Get Started Programming with the Windows API
Q180766 VBA: Sample Code to Determine CD-ROM Drive Letter
The Visual Basic Programmer's Guide

© Microsoft Corporation 2001, All Rights Reserved.
Contributions by Gray McDonald, Microsoft Corporation


Additional query words: VB CD CDROM Locate Drive Find List

Keywords : kbsample kbAPI kbSDKWin32 kbVBp kbVBp500 kbVBp600 kbGrpDSVB kbDSupport
Issue type : kbhowto
Technology : kbWord600Search


Last Reviewed: March 26, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
mn_lh 2001-10-04
  • 打赏
  • 举报
回复
你可以用GetLogicalDriveString更方便

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧