我想实现检测系统上移动设备,检测如果有的话,获取盘符,然后将system.ini 复制进去,因为老师出的题目!
解决方案 »
- patrickkong 被封了? 貌似好久没见了....
- 马赛克问题!!!急啊!!!!高手指点下我应该找什么资料
- 如何获取cpu、硬盘序列号,老问题,但在win98下不行?
- 打印怪问题,有兴趣来看看
- 请问GGJJ,如何将BMP里的图元数据一行一行的读出
- 急,请各位大侠帮忙!ado字段属性问题,Attributes
- 问大家一个关于菜单的问题,超级简单!解决者马上得分!:)
- 如何获得拖动文件的文件名?
- 可以在设计阶段设置menu的tag值吗?
- 用VB作控件,能否给该控件添加菜单?
- VB的OPEN语句无法打开2.5G的文件,提示是 错误号9 下标越界
- 请求帮忙,VB引用EXCEL,遇到类型匹配问题???
简单点的枚举本地存储设备,并判断类型。
Option ExplicitPrivate Const GWL_WNDPROC As Long = -4Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Sub Form_Load()
preWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End SubPrivate Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(hWnd, GWL_WNDPROC, preWndProc)
End Sub'模块
Option ExplicitPrivate Const DBT_DEVICEARRIVAL As Long = &H8000
Private Const DBT_DEVICEQUERYREMOVE As Long = &H8001
Private Const DBT_DEVICEQUERYREMOVEFAILED As Long = &H8002
Private Const DBT_DEVICEREMOVECOMPLETE As Long = &H8004
Private Const DBT_DEVICEREMOVEPENDING As Long = &H8003Private Const WM_DEVICECHANGE As Long = &H219Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPublic preWndProc As LongFunction WndProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'参考这里:http://community.csdn.net/Expert/TopicView3.asp?id=5472147
Select Case msg
Case WM_DEVICECHANGE '设备插入通告
Select Case wParam
Case DBT_DEVICEARRIVAL
Debug.Print "插入"
Case DBT_DEVICEREMOVECOMPLETE
Debug.Print "拔出"
Case DBT_DEVICEQUERYREMOVE
Case DBT_DEVICEQUERYREMOVEFAILED
Case DBT_DEVICEREMOVEPENDING
End Select
End Select
WndProc = CallWindowProc(preWndProc, hWnd, msg, wParam, lParam)
End Function
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 LongPrivate Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6Private Sub Command1_Click()
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) '检查驱动器类型
Debug.Print rtn, JustOneDrive
End If
Loop Until AllDrives = "" Or rtn = DRIVE_CDROM
End Sub
DBT_CONFIGCHANGED The current configuration has changed, due to a dock or undock.
DBT_DEVICEARRIVAL A device has been inserted and is now available.
DBT_DEVICEQUERYREMOVE Permission is requested to remove a device. Any application can deny this request and cancel the removal.
DBT_DEVICEQUERYREMOVEFAILED A request to remove a device has been canceled.
DBT_DEVICEREMOVECOMPLETE A device has been removed.
DBT_DEVICEREMOVEPENDING A device is about to be removed. Cannot be denied.
DBT_DEVICETYPESPECIFIC A device-specific event has occurred.
DBT_QUERYCHANGECONFIG Permission is requested to change the current configuration (dock or undock).
我的想法: 1. 根据盘符来获取硬盘的设备名称,2. 获取设备的特征,从而确定是不是移动磁盘。
不过我不知道该用什么函数。