我想实现检测系统上移动设备,检测如果有的话,获取盘符,然后将system.ini 复制进去,因为老师出的题目!

解决方案 »

  1.   

    复杂点的用Shell Hooks
    简单点的枚举本地存储设备,并判断类型。
      

  2.   

    '窗口
    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
      

  3.   

    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 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
      

  4.   

    倒数第二行改成:Loop Until AllDrives = ""
      

  5.   

    DBT_CONFIGCHANGECANCELED A request to change the current configuration (dock or undock) has been canceled. 
    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).
      

  6.   

    那请问下塞北雪貂,如果有这个U盘的话怎么把system.ini复制进去?
      

  7.   

    塞北雪貂,你把复制system.ini文件这个代码写下,我立刻给分了! 结帖了!
      

  8.   

    Private Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long楼主看看这个API
      

  9.   

    大容量的移动硬盘,GetDriveType 返回的类型是 DRIVE_FIXED. 不能再用这个函数来判断了。
    我的想法: 1. 根据盘符来获取硬盘的设备名称,2. 获取设备的特征,从而确定是不是移动磁盘。
    不过我不知道该用什么函数。