Franz Posted February 24 Share Posted February 24 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 More sharing options...
Franz Posted February 24 Author Share Posted February 24 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. Link to comment Share on other sites More sharing options...
Noobis Posted February 24 Share Posted February 24 Function DriveGetSerial (autoitscript.com) argumentum 1 Link to comment Share on other sites More sharing options...
argumentum Posted February 24 Share Posted February 24 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. Link to comment Share on other sites More sharing options...
Franz Posted February 24 Author Share Posted February 24 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 More sharing options...
ioa747 Posted February 24 Share Posted February 24 how-to-post-code-on-the-forum I know that I know nothing Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 24 Moderators Share Posted February 24 (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 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 More sharing options...
argumentum Posted February 24 Share Posted February 24 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. Link to comment Share on other sites More sharing options...
Franz Posted February 24 Author Share Posted February 24 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 More sharing options...
Alecsis1 Posted February 24 Share Posted February 24 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: Link to comment Share on other sites More sharing options...
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