设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: 好学
打印 上一主题 下一主题

[其它] [求助]用什么代码可以打开E盘?

[复制链接]
11#
 楼主| 发表于 2007-3-19 04:15:00 | 只看该作者
fan0217大哥是这样打开吗?但为什么不行呢?

Private Sub 浏览_Click()
    Call GetCDROMDrive
End Sub


12#
发表于 2007-3-19 04:45:00 | 只看该作者
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
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const DRIVE_CDROM = 5


Public Function GetCDRom() As String

Dim rtn As String
Dim AllDrives As String
Dim JustOneDrive As String

AllDrives = Space$(64) '设置缓冲

rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) '调用函数得到包含所有驱动器的字符串

AllDrives = Left(AllDrives, rtn)

Do
  rtn = InStr(AllDrives, Chr(0))
  If rtn Then                                        '若有的话
     JustOneDrive = Left(AllDrives, rtn)
     AllDrives = Mid(AllDrives, rtn + 1, Len(AllDrives))
     rtn = GetDriveType(JustOneDrive)                '检查驱动器类型
     If rtn = DRIVE_CDROM Then                        '是CD-ROM
        GetCDRom = Left(UCase(JustOneDrive), 2)
        Exit Do
     End If
  End If
Loop Until AllDrives = "" Or rtn = DRIVE_CDROM


If GetCDRom = "" Then
   MsgBox "没有光驱"
   Else
   Call ShellExecute(hwnd, "Open", "", "", GetCDRom, 1)
End If

End Function





[此贴子已经被作者于2007-3-18 20:48:50编辑过]

13#
 楼主| 发表于 2007-3-19 04:51:00 | 只看该作者
可以了!谢谢两位版主![em17][em17][em17]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-10-1 12:50 , Processed in 0.102835 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表