Nuevas NORMAS para el foro

Curso Hacker
Bienvenido(a), Visitante. Favor de ingresar o registrarse.
¿Perdiste tu email de activación? - Julio 06, 2008, 04:55:01
Boton Buscar
Inicio Ayuda Ingresar Registrarse
Visita: Articulos - Juegos Gratis - Da Foros

Comunidad Underground Hispana  |  Programacion  |  Programación  |  Visual Basic y Net (Moderador: ANYD00M)  |  Tema: Detectar Unidades USB 0 Usuarios y 1 Visitante están viendo este tema. « anterior próximo »
Páginas: [1] Ir Abajo Imprimir
Autor Tema: Detectar Unidades USB  (Leído 53 veces)
Deeo
Miembro
*****
Desconectado Desconectado

Mensajes: 108


Ozzy Slave.

MrRaiser@gmail.com
Ver Perfil Email
« en: Mayo 30, 2008, 09:50:36 »

Bueno este código no recuerdo de donde lo saque pero no es mío.
Sirve para detectar cuando se conecta una Unidad USB para ello necesitaremos:

Un modulo, donde colocaremos el siguiente código:

Public Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Declare Function GetLogicalDrives Lib "kernel32" () As Long

'VARIABLE QUE VA A TOMAR EL MOMBRE DE LA UNIDAD
Public UnidadUSB As String

Public Function GetDriveSerial(ByVal sDrive As String) As Long
    sDrive = UCase(Left$(sDrive, 1)) & ":\"
    Call GetVolumeInformation(sDrive, vbNullString, 0, GetDriveSerial, 0, 0, vbNullString, 0)
    UnidadUSB = sDrive
End Function

Public Function IsConnected(ByVal lID As Long) As Boolean
    Dim LDs As Long, Cnt As Long, sDrives As String
    LDs = GetLogicalDrives
    For Cnt = 0 To 25
        If (LDs And 2 ^ Cnt) <> 0 Then
            sDrives = sDrives + Chr$(65 + Cnt)
            If GetDriveType(Trim(Right(sDrives, 1) & ":\")) = 2 Then
                UnidadUSB = Trim(Right(sDrives, 1) & ":\")
            End If
        End If
    Next Cnt
End Function


Y un Formulario, donde colocaremos un Timer y una Label y el siguiente código:

Private Sub Form_Load()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
IsConnected (0)
Label1.Caption = UnidadUSB
End Sub


Bueno espero que les sirva. Salu2.
Deeo
En línea

Páginas: [1] Ir Arriba Imprimir 
Comunidad Underground Hispana  |  Programacion  |  Programación  |  Visual Basic y Net (Moderador: ANYD00M)  |  Tema: Detectar Unidades USB « anterior próximo »
Ir a:  


Ranking-Hits
Powered by SMF 1.1.5 | SMF © 2006-2007, Simple Machines LLC