Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: Hasseds en 21 Junio 2011, 22:01 PM

Título: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 21 Junio 2011, 22:01 PM
Retorno = Seriales de Pen-Drives conectados

Código (vb) [Seleccionar]


Option Explicit

'Function: FlashSerials
'Autor   : Sergio Desanti (Hasseds)
'Thank   : Seba , Cobein, A.Desanti
'Test    : XP (32 BIT) - W7/UAC (32 BIT)
'Return  : Serial(ESN) de Pen-Drives conectados
'
Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As GUID, ByVal Enumerator As Long, ByVal hwndParent As Long, ByVal flags As Long) As Long
Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long


Private Type GUID
   Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(7) As Byte
End Type

Private Type SP_DEVICE_INTERFACE_DATA
   cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
End Type

Private Type SP_DEVINFO_DATA
   cbSize As Long: ClassGuid As GUID: DevInst As Long: Reserved As Long
End Type

Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
   cbSize As Long: strDevicePath As String * 260
End Type

Private Sub Form_Load()
    AutoRedraw = True
    Print FlashSerials
End Sub

Public Function FlashSerials() As String

   Dim TGUID As GUID
   
   Call IIDFromString(StrPtr("{a5dcbf10-6530-11d2-901f-00c04fb951ed}"), TGUID)
   
   Dim hDev As Long
   hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
   If hDev = -1 Then Exit Function

   Dim lCount        As Long
   Dim lSize         As Long
   Dim DEV_DETAIL    As SP_DEVICE_INTERFACE_DETAIL_DATA
   Dim DEV_INFO      As SP_DEVINFO_DATA
   Dim DEV_DATA      As SP_DEVICE_INTERFACE_DATA
   
   DEV_DATA.cbSize = Len(DEV_DATA)
   
   While SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DEV_DATA) <> &H0
     Call SetupDiGetDeviceInterfaceDetail(hDev, DEV_DATA, ByVal &H0, &H0, lSize, ByVal &H0)
     DEV_DETAIL.cbSize = &H5
     DEV_INFO.cbSize = Len(DEV_INFO)
     Call SetupDiGetDeviceInterfaceDetail(hDev, DEV_DATA, DEV_DETAIL, ByVal lSize, &H0, DEV_INFO)
     If UBound(Split(DEV_DETAIL.strDevicePath, "#")) > 1 Then
       FlashSerials = FlashSerials & Split(UCase$(DEV_DETAIL.strDevicePath), "#")(2) & Chr$(&HD)
     End If
     lCount = lCount + 1
   Wend
   
   Call SetupDiDestroyDeviceInfoList(hDev)

End Function






Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Elemental Code en 21 Junio 2011, 23:15 PM
CHAAAAAAAN.
Explicame que es el serial de un pendrive  :-[
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 21 Junio 2011, 23:34 PM
El numero de serie (Proporcionado por el frabricante) de un dispositivo, este deberiá ser unico y no cambiar al formatear, saludos
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 17 Septiembre 2011, 01:08 AM
Agrego (por si el tema le interesó a alguien) un modulo para asociar la letra de unidad con su respectivo Serial (ESN) de Pen Drive.

Nota1: no pude probar como se comporta el código con Discos uSB externos ni con grabadoras USB, lo voy a hacer en cuanto tenga la oportunidad

Nota 2: es posible que no haya que llamar 2 veces a SetupDiGetDeviceInterfaceDetail, creo que RequiredSize As Long (lSize en el codigo) de esta api seria de &H7B para la clase "{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" pero solo pude probar en XP conectando de uno hasta seis PenDrive.

Saludos


MODULO:

Código (vb) [Seleccionar]


Option Explicit

'Modulo: FlashSerial
'Autor: Sergio Desanti (Hasseds)
'Agradecimientos: Seba, Cobein, A.Desanti
'Test: XP (32 BIT) & W7 (32 BIT)
'Retorno:  Letra de unidad y Serial Number(ESN) de Pen Drive conectados
'
Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long

Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long

Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As GUID, ByVal Enumerator As Long, ByVal hwndParent As Long, ByVal flags As Long) As Long
Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long

Private Type STORAGE_DEVICE_NUMBER
   DeviceType As Long: DiskNumber As Long: PartNumber As Long
End Type

Private Type GUID
   Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(7) As Byte
End Type

Private Type SP_DEVICE_INTERFACE_DATA
   cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
End Type

Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
   cbSize As Long: strDevicePath As String * 260
End Type

Public Function FlashSerial(ByVal sLetra As String) As String
 
 sLetra = Left$(UCase$(sLetra), 1) & ":"

 FlashSerial = sLetra & " NO USB"

 Dim RetDeviceIndex    As Long
 RetDeviceIndex = DeviceIndex(sLetra)
 If RetDeviceIndex < 0 Then Exit Function ' " -1 -2 -3 en DeviceIndex"
 
 Dim TGUID             As GUID
 Call IIDFromString(StrPtr("{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"), TGUID)
 
 Dim hDev              As Long
 hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
 If hDev = -1 Then: Exit Function
 
 Dim lCount            As Long
 Dim lSize             As Long
 Dim DTA               As SP_DEVICE_INTERFACE_DATA
 Dim DTL               As SP_DEVICE_INTERFACE_DETAIL_DATA

 DTA.cbSize = Len(DTA)
 DTL.cbSize = &H5
   
 Do While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DTA) = &H0&)
   Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, ByVal &H0&, &H0, lSize, ByVal &H0&)
   Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, DTL, ByVal lSize, &H0&, ByVal &H0&)
   If InStr(UCase$(DTL.strDevicePath), "USB") Then
     If DeviceIndex(DTL.strDevicePath, True) = RetDeviceIndex Then
       If UBound(Split(DTL.strDevicePath, "#")) > 1 Then
         FlashSerial = sLetra & Split(UCase$(DTL.strDevicePath), "#")(2)
         Exit Do
       End If
     End If
   End If
   lCount = lCount + 1
 Loop
 
 Call SetupDiDestroyDeviceInfoList(hDev)
 
End Function

Public Function DeviceIndex(ByVal sLetra As String, Optional strDevicePath As Boolean) As Long
   
 Dim hdh As Long, br As Long, SDN As STORAGE_DEVICE_NUMBER
 
 If Not strDevicePath Then sLetra = "\\.\" & Left$(UCase$(sLetra), 1) & ":"

 hdh = CreateFile(sLetra, &H0&, &H3&, ByVal &H0&, &H3&, &H0&, &H0&) ': MsgBox hdh, , "hdh"
 If Not (hdh = -1) Then
     If DeviceIoControl(hdh, &H2D1080, &H0&, &H0&, SDN, Len(SDN), br, ByVal &H0&) Then
         If SDN.DeviceType = 7 Then
             DeviceIndex = SDN.DiskNumber  ' Retorno DeviceIndex
         Else
             DeviceIndex = -3   ' No es GUID 53f56307-b6bf-11d0-94f2-00a0c91efb8b
         End If
     Else
         DeviceIndex = -2  ' Floppy o DeviceIoControl = 0 (GetLastError)
     End If
      Call CloseHandle(hdh)
 Else
     DeviceIndex = -1  ' Unidad sin dispositivo o CreateFile = -1 (GetLastError)
 End If

End Function






Código (vb) [Seleccionar]


Option Explicit

Private Sub Form_Load()

     MsgBox FlashSerial("f")

End Sub










Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 6 Octubre 2011, 22:04 PM
Funciona en una cuenta de usuario, cuando usas WMI necesitas permisos  :D lo utilizaré, aún no entiendo que es eso de hook en el formulario. Pero averiguaré.

Saludos.
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 7 Octubre 2011, 02:57 AM
Si , creo que tambien funciona con UAC activado (tal vez alguien que lo pueda probar en W7 nos informe de esto)

Un ejemplo de Hook de lo mas de lo mas simple, si te sirve... te toca optimizar y adaptar a lo tuyo.



MODULO



Option Explicit

'Function: FlashSerials
'Autor   : Sergio Desanti (Hasseds)
'Thank   : Seba , Cobein, A.Desanti
'Test    : XP (32 BIT) - W7 (32 BIT)
'Return  : Serial(ESN) de Pen-Drives conectados
'

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const GWL_WNDPROC = -4
Private Const WM_DEVICECHANGE As Long = 537              'Cambios en un dispositivo
Private Const DBT_DEVICEARRIVAL As Long = 32768          'Cuando se conecta uno nuevo
Private Const DBT_DEVICEREMOVECOMPLETE As Long = 32772   'Cuando se desconecta uno
Private Const DBT_DEVTYP_VOLUME As Integer = 2           'Logical volume, cualquier unidad de almacenamiento nueva.

Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As GUID, ByVal Enumerator As Long, ByVal hwndParent As Long, ByVal flags As Long) As Long
Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long

Private Type GUID
  Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(7) As Byte
End Type

Private Type SP_DEVICE_INTERFACE_DATA
  cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
End Type

Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
  cbSize As Long: strDevicePath As String * 260
End Type

Dim hHook As Long

Public Sub StartHook(hWnd As Long)
   hHook = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub StopHook(hWnd As Long)
   SetWindowLong hWnd, GWL_WNDPROC, hHook
   hHook = 0
End Sub

Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   WindowProc = CallWindowProc(hHook, hWnd, uMsg, wParam, lParam)
   If uMsg = WM_DEVICECHANGE Then
     If wParam = DBT_DEVICEARRIVAL Then
       Form1.Cls
       Form1.Print "Conectaron", Time
       Form1.Print
       Form1.Print FlashSerials
     ElseIf wParam = DBT_DEVICEREMOVECOMPLETE Then
       Form1.Cls
       Form1.Print "Desconectaron", Time
       Form1.Print
       Form1.Print FlashSerials
     End If
   End If
End Function

Public Function FlashSerials() As String

  Dim TGUID As GUID

  Call IIDFromString(StrPtr("{a5dcbf10-6530-11d2-901f-00c04fb951ed}"), TGUID)

  Dim hDev As Long
  hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
  If hDev = -1 Then Exit Function

  Dim lCount       As Long
  Dim lSize        As Long
  Dim DTL          As SP_DEVICE_INTERFACE_DETAIL_DATA
  Dim DTA          As SP_DEVICE_INTERFACE_DATA

  DTA.cbSize = Len(DTA)
  DTL.cbSize = &H5

  While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DTA) = &H0)
    Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, ByVal &H0, &H0, lSize, ByVal &H0)
    Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, DTL, ByVal lSize, &H0, ByVal &H0)
    If UBound(Split(DTL.strDevicePath, "#")) > 1 Then
      FlashSerials = FlashSerials & Split(UCase$(DTL.strDevicePath), "#")(2) & Chr$(&HD)
    End If
    lCount = lCount + 1
  Wend

  Call SetupDiDestroyDeviceInfoList(hDev)
 
  If FlashSerials = "" Then FlashSerials = "No hay conexiones"
 
End Function





FORM



Option Explicit

Private Sub Form_Load()
AutoRedraw = True
Print FlashSerials
Call SetWindowPos(Form1.hWnd, &HFFFF, &H0, &H0, &H0, &H0, &H3) 'form on top
Call StartHook(hWnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Call StopHook(hWnd)
End Sub






http://www.virustotal.com/file-scan/report.html?id=4e03da8a806215953259ea3291bc79d7cab8226fdabb14765efdd81b4b94eae1-1317934469




Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: BlackZeroX en 7 Octubre 2011, 03:30 AM
.
No recuerdo bien pero ya habia visto un codigo asi hace tiempo... igual no recuerdo donde... jaja a mi biblioteca.

Dulces Lunas!¡.
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 7 Octubre 2011, 03:40 AM
Entendi que hook es detectar las acciones que el usuario realiza mientras el programa esta activo, en este caso el USB conectado o no.

Me sirve, claro que si, como decimos en mi barrio: Gracielas  ;D

Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 7 Octubre 2011, 03:43 AM
mmm... me parece q me fuí al carajo  >:D


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: .:UND3R:. en 7 Octubre 2011, 05:52 AM
es una excelente herramienta para evitar el cracking de alguna forma, vender un software con dongle en donde el programa pide un serial y un pendrive conectado este serial es algún algoritmo del serial del pendrive por lo que si se coloca el serial este al pasar por algunos cálculos debería ser el mismo serial que el del pendrive, si no retorna serial incorrecto o llave USB incorrecta



aclaro que es una idea de la funcionalidad que se le puede dar, no necesariamente es para eso,Saludos

PD: un programa que permita una serie de pendrive determinados conectarce al PC

sistema de seguirdad para aislar troyanos.

etc

Saludos

Saludos
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 7 Octubre 2011, 21:36 PM
Cita de: Hasseds en  7 Octubre 2011, 03:43 AM
mmm... me parece q me fuí al carajo  >:D




?  :xD
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 7 Octubre 2011, 21:49 PM
Nada, leí mal y me equivoqué en una respuesta, pero ya está editado. xD



Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 8 Noviembre 2011, 17:58 PM
Intente pasar tu code a VB2005 yo utilizo el Sharpdevelop
Estoy averiguando como utilizar la API
SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)

me da problemas con AddressOf WindowProc si tienes alguna recomendación, algún link que puedas compartir te lo agradeceria. Seguiré averiguando.

Saludos


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 8 Noviembre 2011, 19:05 PM
En VB.Net no tengo ni idea de como capturar los mensajes del Form, pero mirá este link, aparentemente es un hook al mouse... tal vez te sirva de ejemplo para AddressOf .

http://support.microsoft.com/kb/319524  (http://support.microsoft.com/kb/319524)






Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 9 Noviembre 2011, 04:11 AM
Funciona muy bien, gracias por el dato, seria muy bueno pasar tu code de los seriales a VB2005. Yo uso el http://www.icsharpcode.net/OpenSource/SD/ para no pagar licencia.

Gracias.
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 4 Diciembre 2011, 20:09 PM
Hola tengo una consulta la clase: "{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" me detecta hasta las unidades de disco IDE, si alguien tuviera discos SATA para ver si los detecta
Código (vb) [Seleccionar]

Public Function FlashSerials() As String
    Dim cad As String
   Dim TGUID As GUID

   Call IIDFromString(StrPtr("{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"), TGUID)
     
   Dim hDev As Long
   ' puntero a la clase de los USB
   hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)

   If hDev = -1 Then Exit Function

   Dim lCount       As Long
   Dim lSize        As Long
   Dim DTL          As SP_DEVICE_INTERFACE_DETAIL_DATA
   Dim DTA          As SP_DEVICE_INTERFACE_DATA

   DTA.cbSize = Len(DTA)
   DTL.cbSize = &H5
   lCount = &H0
     
   While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DTA) = &H0)
     
     Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, ByVal &H0, &H0, lSize, ByVal &H0)
     
     Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, DTL, ByVal lSize, lSize, ByVal &H0)
     
     If UBound(Split(DTL.strDevicePath, "#")) > 1 Then
        cad = cad & Split(UCase$(DTL.strDevicePath), "#")(1) & _
         " - " & Split(UCase$(DTL.strDevicePath), "#")(2) & Chr$(&HD)
        'cad = cad & DTL.strDevicePath & Chr(10)
     End If
     
     lCount = lCount + 1
   Wend

   Call SetupDiDestroyDeviceInfoList(hDev)
   FlashSerials = cad
   If FlashSerials = "" Then FlashSerials = "No hay conexiones"
   
End Function
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 4 Diciembre 2011, 22:24 PM
Hola Maurice_Lupin , la clase 53f56307-b6bf-11d0-94f2-00a0c91efb8b si detecta los discos Sata 1 y sata 2, todavia no pude probar con Sata 3 pero seguramente tambien los detecta ya que es la misma interface.

Esta clase tambien detecta (o enumera mejor dicho) Discos IDE, ZIP de interface IDE y Dispositivos de almacenamiento USB... por lo tanto deberás filtrar los retornos de acuerdo a lo que quieras listar, por ejemplo en el codigo original solo listé la interface USB

If InStr(UCase$(DTL.strDevicePath), "USB") Then      

http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1664147#msg1664147 (http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1664147#msg1664147)



Nota: Las interfaces "IDE" & Sata no retornan el Serial verdadero por esta vía... A Diferencia de la interface USB que sí se puede obtener con este método


La clase a5dcbf10-6530-11d2-901f-00c04fb951ed solo enumera Dispositivos de almacenamiento USB, por lo tanto no hay que "filtrar retornos"
http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1629437#msg1629437 (http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1629437#msg1629437)








Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 5 Diciembre 2011, 06:51 AM
Gracias Hasseds, usando WMI me devuelve casi el mismo serial de IDE que utilizando la clase 53f56307-b6bf-11d0-94f2-00a0c91efb8b , estas seguro que no es el serial verdadero?  :-[

Saludos.

Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: BlackZeroX en 5 Diciembre 2011, 09:12 AM
.
Aclarando un punto crucial es que NO SE LE CONOCE COMO CLASES son GUID esos identificadores...

Dulces Lunas!¡.
Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 5 Diciembre 2011, 18:52 PM
Sí, en adelante será mejor referirse a estas clases de dispositivos como GUID.




Cita de: Maurice_Lupin en  5 Diciembre 2011, 06:51 AM

estas seguro que no es el serial verdadero?  :-[


Segurísimo !!!


Seriales de Hard Disk conectados (Solo funciona como usuario Administrador ):


Código (vb) [Seleccionar]


Option Explicit

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function: SerialHD
' Autor: Adrian Desanti (Dessa)
' Creditos: es una adaptacion a mis necesidades de una clase de Antonio Giuliana
' Agradecimientos: Karcrak (IsAdministrador)
' Requisitos : Windows NT + Administrador
' Rertorno: retorna el serial verdadero de Discos IDE o S-ATA conectados
' Serial verdadero: Es el que figura en la etiqueta del Disco y no cambia al formatear
' Fecha : V.2 Septiembre 2010
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Private Declare Function CheckTokenMembership Lib "ADVAPI32" (ByVal TokenHandle As Long, ByVal pSidToCheck As Long, ByRef IsMember As Boolean) As Long

Private Declare Function GetVersion Lib "KERNEL32" () As Long
Private Declare Function CreateFile Lib "KERNEL32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl Lib "KERNEL32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)

Private Type IDEREGS
   bFeaturesReg As Byte: bSectorCountReg As Byte: bSectorNumberReg As Byte: bCylLowReg As Byte: bCylHighReg As Byte: bDriveHeadReg As Byte: bCommandReg As Byte: bReserved As Byte
End Type
Private Type SENDCMDINPARAMS
   cBufferSize As Long: irDriveRegs As IDEREGS: bDriveNumber As Byte: bReserved(1 To 3) As Byte: dwReserved(1 To 4) As Long
End Type
Private Type DRIVERSTATUS
   bDriveError As Byte: bIDEStatus As Byte: bReserved(1 To 2) As Byte: dwReserved(1 To 2) As Long
End Type
Private Type SENDCMDOUTPARAMS
   cBufferSize As Long: DStatus As DRIVERSTATUS: bBuffer(1 To 512) As Byte
End Type

Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByVal ClassGuid As Long, ByVal Enumerator As Long, ByVal HwndParent As Long, ByVal flags As Long) As Long
Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long

Private Type GUID
   Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(0 To 7) As Byte
End Type

Private Type SP_DEVICE_INTERFACE_DATA
   cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
End Type


Private Sub Form_Load()
 
 If (GetVersion And &HFF) > &H5 Then
   If App.LogMode = 0 Then
       MsgBox "En Vista o Seven ejecutar compilado en modo Administrador"
       End
   End If
 End If
 
 
 AutoRedraw = True
 FontBold = True
 Caption = ""
 Print SerialHD()
 
 
 
End Sub

Public Function SerialHD() As String

 If (GetVersion And &HFF) < 5 Then
   SerialHD = "Sistema Operativo No válido"
   Exit Function
 End If
 
 If IsAdministrador = False Then
   SerialHD = "Se requiere usuario Administrador"
   Exit Function
 End If
 
 Dim RetDiskCount  As Long
 
 RetDiskCount = DiskCount()
 
 If RetDiskCount < 0 Then
   SerialHD = "DiskCount No válido"
   Exit Function
 End If
 
 Dim nDisco        As Long
 Dim hdh           As Long
 Dim hddfr         As Byte
 Dim hddln         As Byte
 Dim bin           As SENDCMDINPARAMS
 Dim bout          As SENDCMDOUTPARAMS
 Dim br            As Long
 Dim x             As Byte
 Dim s             As String
   
 For nDisco = 0 To RetDiskCount - 1 ' los ciclos del For serán solo la cantidad de "PhysicalDrive" conectados
   
     hdh = CreateFile("\\.\PhysicalDrive" & nDisco, &H3, &H0, &H0, &H3, &H0, &H0)
 
     If hdh = -1 Then
         If nDisco = 0 Then
             SerialHD = " IDE " & nDisco & " = " & "Error en CreateFile" & vbNewLine
         Else
             SerialHD = SerialHD & " IDE " & nDisco & " = " & "Error en CreateFile" & vbNewLine
         End If
     Else
         hddfr = 21 ' Posicion en el buffer del SerialNumber
         hddln = 20 ' Tamaño resrvado en el buffer para el SerialNumber
         
         Call ZeroMemory(bin, Len(bin))
         Call ZeroMemory(bout, Len(bout))
   
         With bin
             .bDriveNumber = nDisco
             .cBufferSize = 512
           With .irDriveRegs
               If (nDisco And 1) Then
                   .bDriveHeadReg = &HB0
               Else
                   .bDriveHeadReg = &HA0
               End If
               .bCommandReg = &HEC
               .bSectorCountReg = 1
               .bSectorNumberReg = 1
           End With
         End With
 
         'DFP_RECEIVE_DRIVE_DATA = &H7C088
         Call DeviceIoControl(hdh, &H7C088, bin, Len(bin), bout, Len(bout), br, 0)
     
         s = ""
         For x = hddfr To hddfr + hddln - 1 Step 2
             If bout.bBuffer(x + 1) = 0 Then Exit For
             s = s & Chr(bout.bBuffer(x + 1))
             If bout.bBuffer(x) = 0 Then Exit For
             s = s & Chr(bout.bBuffer(x))
         Next x
         Call CloseHandle(hdh)
 
         If Trim$(s) <> "" Then
             SerialHD = SerialHD & " IDE " & nDisco & " = " & Trim$(s) & vbNewLine
         End If
     End If

 Next nDisco

End Function

Private Function DiskCount() As Long
   
   Dim TGUID   As GUID
   Dim hDev    As Long
   
   Call IIDFromString(StrPtr("{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"), TGUID)
   
   '&H12 ===> DIGCF_PRESENT = &H10 Or DIGCF_DEVICEINTERFACE = &H2
   hDev = SetupDiGetClassDevs(VarPtr(TGUID), &H0, &H0, &H12)
   
   If hDev = -1 Then
     DiskCount = -1
     Exit Function
   End If
   
   Dim Cnt As Long
   Dim DTA  As SP_DEVICE_INTERFACE_DATA
   DTA.cbSize = Len(DTA)
   
   While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, Cnt, DTA) = &H0)
       Cnt = Cnt + 1
   Wend
 
   Call SetupDiDestroyDeviceInfoList(hDev)
       
   DiskCount = Cnt

End Function

Private Function IsAdministrador() As Boolean
  Dim SID(1)  As Currency
  SID(0) = 36028797018964.0193@
  SID(1) = 233646220.9056@
  Call CheckTokenMembership(&H0, VarPtr(SID(0)), IsAdministrador)
End Function






Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 6 Diciembre 2011, 05:41 AM
 :( pensé que eran verdaderos, gracias, habrá que ejecutar como administrador  :xD

Saludos.