Jump to content

Getting serial number from Samsung mobile device without adb


Inpho
 Share

Recommended Posts

Hi All,

I didn't know where to put this; my apologies if this is the wrong location.

When you plug a Samsung mobile device (phone, tablet, etc.) into the USB of a Windows PC, you can right-click the device in My Computer and select Properties. Here, it will show you the correct serial number of the device. Clearly Windows doesn't use adb to get the SN so I'm stuck at how to get the SN without adb and where the device doesn't have a drive letter assigned to it.

When I last picked this up, I tried seemingly everything I could from wmi(?) and winmgmts(?) but either it's hidden cloak-and-dagger style or I can't see the forest for the trees...

Does anyone know what API Windows uses when getting the serial number of a device Windows calls a Portable Media Player?

20191009_135630.jpg

Link to comment
Share on other sites

So I went down a rabbit hole, and I'm still looking, but I got to here eventually: https://docs.microsoft.com/en-us/windows/win32/api/mswmdm/nf-mswmdm-iwmdmdevice-getserialnumber

I think you might need to install a special SDK to use the method, but I'm honestly not sure.

As an alternate solution... you might be able to monitor the registry. I think that what this person did. I have too many USB hubs or something at work and I can't find my phone after plugging it in (Galaxy S7), but you might be able to. To anyone on Win10, it looks like the registry matches pretty well to Win7. (It looks like you have Win7, right?)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

I'm using Win7 to develop the tool, but the tool runs on a mix of Windows 7 and 10 machines. This tool is called Hubble (as it inspects Samsung Galaxy devices heh).

I work in the industry and have almost infinite devices to test on (from Galaxy S/S1 to Galaxy Folds) so I'll look into your advice tomorrow as it's almost EOD for me.

Thanks for the info :)

Link to comment
Share on other sites

I'm making some progress; this "solution" works on my work PC but I'll have to travel to the workshop to get some technicians to test this tomorrow.

I'm doubting this is universal but here it is for now. Returns serials from ALL devices inserted since last logon by the looks of it so an internal exclusion list will have to be added to as it goes along. More testing tomorrow.

Global Const $sStripClass = "#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"
Global Const $sStripIdentifier = "\??\USB#VID_04E8&PID_6860#"

Func DevicesGet()

    Local $sSubKey = ""
    Local $sKeys = ""
    Local $aKeys

    ; Loop from 1 to 10 times, displaying registry keys at the particular instance value.
    For $i = 1 To 10
        $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_04E8&PID_6860", $i)
        If @error Then ExitLoop
        $sKeys &= $sSubKey & ","
    Next
    If $sKeys <> "" Then
        $sKeys = StringTrimRight($sKeys, 1)
        $aKeys = StringSplit($sKeys, ",")
    EndIf

    Return($aKeys)

EndFunc   ;==>Example

$aSerials = DevicesGet()

For $i = 1 To UBound($aSerials) - 1

    $s = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_04E8&PID_6860\" & $aSerials[$i] & "\Device Parameters", "SymbolicName")
    $s = _StringTrimLeft($s, "#", 0, 2)

    $s = _StringLeft($s, "#")

    ConsoleWrite($s & @CRLF)

Next

; #FUNCTION# ====================================================================================================================
; Name ..........:  _StringTrimLeft
; Description ...:  Searches for a string inside a string, then removes everything on the left of that string
; Syntax ........:  _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1])
; Parameters ....:  $sString            - a string value. The string to search inside.
;                   $sRemove            - a string value. The string to search for.
;                   $iCaseSense         - an integer value. Flag to indicate if the operations should be case sensitive.
;                   $iOccurrence        - an integer value. Which occurrence of the substring to find in the string. Use a
;                                         negative occurrence to search from the right side.
; Return values .:  Success             - String
;                   Failure             - Empty string as returned from StringTrimLeft()
; Author ........:  Sam Coates
; ===============================================================================================================================
Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1)

    Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1))

EndFunc   ;==>_StringTrimLeft

; #FUNCTION# ====================================================================================================================
; Name ..........:  _StringLeft
; Description ...:  Searches for a string inside a string, then removes everything on the right of that string
; Syntax ........:  _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1])
; Parameters ....:  $sString            - a string value. The string to search inside.
;                   $sRemove            - a string value. The string to search for.
;                   $iCaseSense         - an integer value. Flag to indicate if the operations should be case sensitive.
;                   $iOccurrence        - an integer value. Which occurrence of the substring to find in the string. Use a
;                                         negative occurrence to search from the right side.
; Return values .:  Success             - String
;                   Failure             - Empty string as returned from StringLeft()
; Author ........:  Sam Coates
; ===============================================================================================================================
Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1)

    Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1))

EndFunc   ;==>_StringLeft

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...