Jump to content

Read Serial Number (extern drive)


Recommended Posts

Hello, i want to create a little tool to sync my files for all my drives and i want to make it as safe as possible.

 

In my special case i want to read the Serial number for  each drive and then i want to execute my sync program, but unfortunately the WMI method doesnt work for me.

 

 

For example:
My intern Drive / Correct Serial
Modell: Samsung SSD 850 EVO 500GB
Seriennummer: S2RBNXXXXXXX

Extern drive 1
Modell: WDC WD40 EZAZ-00SF3B0 USB Device
Seriennummer: 152D00539000

Extern drive 2
Modell: WDC WD40 EZAZ-00SF3B0 USB Device
Seriennummer: 152D00539001

Extern drive 3
Modell: WDC WD40 EZAZ-00SF3B0 USB Device
Seriennummer: 152D00539002

Extern drive 4
Modell: WDC WD40 EZAZ-00SF3B0 USB Device
Seriennummer: 152D00539003

 

 

Here is my Code...

#include <Array.au3>

Local $colItems, $objWMIService, $objItem

$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL")

If IsObj($colItems) Then
    For $objItem In $colItems
        ConsoleWrite("Modell: " & $objItem.Model & @CRLF)
        ConsoleWrite("Seriennummer: " & $objItem.SerialNumber & @CRLF)
    Next
Else
    MsgBox(16, "Error", "No drives Found.")
EndIf
 

 

Crystal Disk Info or other Tools can read the Correct serial so it should be possible.


Thanks for any help ♥

Link to comment
Share on other sites

4 hours ago, Franz said:

Seriennummer: S2RBNXXXXXXX

NVMe drives need coding done to get proper HW S/N. Even the OS ( as you've seen in WMI ) needs more coding.

Use the DriveGetLabel(). Or both, DriveGetSerial() & DriveGetLabel() together to assure uniquely generated identifiers. 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

DriveGetSerial does not work for my extern drives.

 

Thats why i search for a better solution, but i think i have a decent solution rn.

Install smartmontools-7.4-1


and here is my Batch.


@echo off
echo Fuehre smartctl für /dev/sda aus...
smartctl -i /dev/sda | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"
echo.
echo  Fuehre smartctl für /dev/sdb aus...
smartctl -i /dev/sdb | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"

echo.
echo  Fuehre smartctl für /dev/sdc aus...
smartctl -i /dev/sdc | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"

echo.
echo  Fuehre smartctl für /dev/sdd aus...
smartctl -i /dev/sdd | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"

Link to comment
Share on other sites

  • Moderators
15 minutes ago, Franz said:

DriveGetSerial does not work for my extern drives.

 

Thats why i search for a better solution, but i think i have a decent solution rn.

Install smartmontools-7.4-1


and here is my Batch.


@echo off
echo Fuehre smartctl für /dev/sda aus...
smartctl -i /dev/sda | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"
echo.
echo  Fuehre smartctl für /dev/sdb aus...
smartctl -i /dev/sdb | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"

echo.
echo  Fuehre smartctl für /dev/sdc aus...
smartctl -i /dev/sdc | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"

echo.
echo  Fuehre smartctl für /dev/sdd aus...
smartctl -i /dev/sdd | findstr /C:"Device Model" /C:"Serial Number" >> "%~dp0\smartctl_output.txt"

That's for Windows OS? 😶

Edit:

No wonder I don't recognize it, smartctl is 3rd party.

You should just be able to use Run() (with $STDOUT_CHILD in 4th parameter) in conjunction with StdoutRead to get the same data from that 3rd party app rather than running a batch.  There you can just parse the data.  Other than that, I'm completely out of suggestions as I haven't worked with drive information since 2006.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

3 hours ago, SmOke_N said:

That's for Windows OS? 😶

Edit:

No wonder I don't recognize it, smartctl is 3rd party.

You should just be able to use Run() (with $STDOUT_CHILD in 4th parameter) in conjunction with StdoutRead to get the same data from that 3rd party app rather than running a batch.  There you can just parse the data.  Other than that, I'm completely out of suggestions as I haven't worked with drive information since 2006.

Win10 and yes smartctl is a 3rd party application.

 

Thanks for that Tip :)

Link to comment
Share on other sites

Hello!  Try something like this

Opt('MustDeclareVars', True)

Local $colItems, $objWMIService, $objItem

$objWMIService = ObjGet("winmgmts:")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL")
;
If IsObj($colItems) Then
    For $objItem In $colItems
        ConsoleWrite("Model: " & $objItem.Model & @CRLF)
        ConsoleWrite("S/N  : " & StringStripWS($objItem.SerialNumber, 3) & @CRLF) ; cut out excessive spaces
        ConsoleWrite(@CRLF) ; make output easier to read
    Next
    ConsoleWrite("Done" @CRLF)
  Else
    MsgBox(16, "Error", "No drives Found.")
EndIf
;
Exit

All my disks present:

ttDisk.png

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...