Vb.Net - UpdateDriverForPlugAndPlayDevices

时间:2014-03-17 09:49:19

标签: vb.net api driver


我尝试使用UpdateDriverForPlugAndPlayDevices来安装驱动程序 但我只是获得"没有更多数据可用"错误。 请帮帮我

代码:

 Const Driver_TEMP_Path As String = "C:\AdbDriver\android_winusb.inf"
Const INSTALLFLAG_FORCE = &H1
Const INSTALLFLAG_READONLY = &H2
Const INSTALLFLAG_NONINTERACTIVE = &H4
Const INSTALLFLAG_BITS = &H7
Private Declare Function sysUpdateDriverForPlugAndPlayDevices Lib "newdev.dll" Alias "UpdateDriverForPlugAndPlayDevicesA" (ByVal hwndParent As Long, ByVal HardwareId As String, ByVal FullInfPath As String, ByVal InstallFlags As Long, ByRef bRebootRequired As Boolean) As Boolean
Function InstallDeviceDriver(device As USBDeviceInfo, hwnd As Long) As Boolean        
    Dim result As Boolean
    Dim RebootReuqired As Boolean
    If Not My.Computer.FileSystem.FileExists(Driver_TEMP_Path) Then
        MessageBox.Show("Bot fOUnd")
    End If
    result = sysUpdateDriverForPlugAndPlayDevices(hwnd, "USB\VID_0B05&PID_4C91&MI_01", Driver_TEMP_Path, INSTALLFLAG_FORCE, RebootReuqired)
    If Not result Then
        Dim errorCode As Integer = Err.LastDllError
        Dim msg As String = "Unknown"
        Select Case errorCode
            Case 2
                msg = "File Not Found"
            Case 1004
                msg = "Invald Flags"
            Case 259
                msg = "No More Data Available"
            Case -536870389
                msg = "No Such device"

        End Select
        MessageBox.Show(Err.LastDllError & ": " & msg)
    End If
    Return result
End Function

1 个答案:

答案 0 :(得分:0)

修复您的PInvoke声明。

Private Declare Auto Function sysUpdateDriverForPlugAndPlayDevices Lib "newdev.dll" Alias "UpdateDriverForPlugAndPlayDevices" (ByVal hwndParent As IntPtr, ByVal HardwareId As String, ByVal FullInfPath As String, ByVal InstallFlags As Integer, <Out()> ByRef bRebootRequired As Boolean) As Boolean
相关问题