Jump to content

Get Home DiskDrive SerialNumber


Go to solution Solved by Andreik,

Recommended Posts

Posted
1 hour ago, Nine said:

Try powershell :

Get-PhysicalDisk | Select-Object FriendlyName, DeviceID, SerialNumber, AdapterSerialNumber

AdapterSerialNumber looks good.

nice, must be we look for it in wmi classes

Posted (edited)

I didn't read all the posts in this thread.

I found an old WMI script which returns the s/n:

Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")

MsgBox(0, "Test", WMI_GetHDDSN("."))

Func WMI_GetHDDSN($host, $usr = "", $pass = "") ;coded by UEZ 2011
    If $host = "." Then $host = "localhost"
    Local $HDD_SN
    Local $ping = Ping($host, 1000)
    If @error Then Return SetError(1, 0, -1)
    Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
    Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", 128)
    If @error Then Return SetError(2, 0, -1)
    Local $colItems = $objWMIService.ExecQuery("SELECT Model, Name, SerialNumber FROM Win32_DiskDrive WHERE MediaType='Fixed hard disk media'", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $HDD_SN &= "Model: " & $objItem.Model & ", S/N: " & WMI_GetHDDSN2(StringMid($objItem.Name, 5), $host, $usr, $pass) & @LF
        Next
    Else
        Return SetError(3, 0, -1)
    EndIf
    Return $HDD_SN
EndFunc

Func WMI_GetHDDSN2($Tag, $host, $usr = "", $pass = "") ;coded by UEZ 2011
    Local $HDD_SN
    Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
    Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", 128)
    Local $colItems = $objWMIService.ExecQuery("SELECT SerialNumber,Tag FROM Win32_PhysicalMedia WHERE Tag LIKE '%" & $Tag & "%'", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
;~          ConsoleWrite($objItem.Tag & @LF)
            $HDD_SN = $objItem.SerialNumber
        Next
    Else
        Return SetError(3, 0, -1)
    EndIf
    Return $HDD_SN
EndFunc

Func ObjErrorHandler()
     ConsoleWrite(  "A COM Error has occured!" & @CRLF  & @CRLF & _
                                "err.description is: "    & @TAB & $oErrorHandler.description    & @CRLF & _
                                "err.windescription:"     & @TAB & $oErrorHandler & @CRLF & _
                                "err.number is: "         & @TAB & Hex($oErrorHandler.number, 8)  & @CRLF & _
                                "err.lastdllerror is: "   & @TAB & $oErrorHandler.lastdllerror   & @CRLF & _
                                "err.scriptline is: "     & @TAB & $oErrorHandler.scriptline     & @CRLF & _
                                "err.source is: "         & @TAB & $oErrorHandler.source         & @CRLF & _
                                "err.helpfile is: "       & @TAB & $oErrorHandler.helpfile       & @CRLF & _
                                "err.helpcontext is: "    & @TAB & $oErrorHandler.helpcontext & @CRLF _
                            )
EndFunc

 

I don't know if this is what you guys are looking for.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
×
×
  • Create New...