Franz Posted February 24, 2024 Posted February 24, 2024 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 ♥
Franz Posted February 24, 2024 Author Posted February 24, 2024 As i know is Crystal disk info using the ATA Protocol but iam not that deep into programing, if possible Autoit or C# would be nice for this tool.
Noobis Posted February 24, 2024 Posted February 24, 2024 Function DriveGetSerial (autoitscript.com) argumentum 1
argumentum Posted February 24, 2024 Posted February 24, 2024 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.
Franz Posted February 24, 2024 Author Posted February 24, 2024 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"
ioa747 Posted February 24, 2024 Posted February 24, 2024 how-to-post-code-on-the-forum I know that I know nothing
Moderators SmOke_N Posted February 24, 2024 Moderators Posted February 24, 2024 (edited) 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 February 24, 2024 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.
argumentum Posted February 24, 2024 Posted February 24, 2024 54 minutes ago, SmOke_N said: ... Run() (with $STDOUT_CHILD in 4th parameter) ... Try RunWaitEx() by this guy, ...what's his name, ... yes @argumentum. It's easier to use. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Franz Posted February 24, 2024 Author Posted February 24, 2024 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
Alecsis1 Posted February 24, 2024 Posted February 24, 2024 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:
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now