ramzi2015 Posted April 19, 2021 Posted April 19, 2021 I need to show the printed serial number of an external usb hard drive using c# . I have found many sources in "github" but the returned serial number is not correct. the only program that gave me the correct serial number is "CrystalDiskInfo" which is open source but written in c ++ which I do not understand. Here is an example with "CrystalDiskInfo" with the correct result: Thanks for help
kao Posted April 19, 2021 Posted April 19, 2021 Use WMI. http://csharphelper.com/blog/2017/10/get-hard-drive-serial-number-c/
ramzi2015 Posted April 19, 2021 Author Posted April 19, 2021 3 hours ago, kao said: Use WMI. http://csharphelper.com/blog/2017/10/get-hard-drive-serial-number-c/ Thanks for the link , I have already used several sources but the serial number is still wrong and do not forget that it is an external Usb hard drive what can make things more complicated. This is an image as a proof:
kao Posted April 19, 2021 Posted April 19, 2021 (edited) 24 minutes ago, ramzi2015 said: do not forget that it is an external Usb hard drive You never mentioned that. USB enclosures are tricky, some of them they report their own serial numbers and some - serial numbers of the actual hard disk. My WD Book enclosure works fine with the code I suggested earlier. Try running in command prompt: wmic diskdrive get Name,Model,SerialNumber,Size,Status If you don't see the correct information there, then C# application will not be able to get it without writing a lot of specific code (like Crystal Disk Info). Edited April 19, 2021 by kao sometimes -> some of them 1
ramzi2015 Posted April 19, 2021 Author Posted April 19, 2021 39 minutes ago, kao said: You never mentioned that. USB enclosures are tricky, some of them they report their own serial numbers and some - serial numbers of the actual hard disk. My WD Book enclosure works fine with the code I suggested earlier. Try running in command prompt: wmic diskdrive get Name,Model,SerialNumber,Size,Status If you don't see the correct information there, then C# application will not be able to get it without writing a lot of specific code (like Crystal Disk Info). No luck, the serial number is still incorrect with the "wmic" command. I think things are more complicated than I thought. So, I will try to use a third party tool to get the correct result. Thank you anyway
Kurapica Posted April 20, 2021 Posted April 20, 2021 (edited) Probably you don't have admin rights. Try this : GetVolumeInformationA >> https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa Old school never fails. https://www.codeproject.com/Articles/16941/Get-Physical-HDD-Serial-Number-without-WMI C# : https://overcoder.net/q/2170341/как-использовать-ioctlscsiminiport-через-deviceiocontrol-из-c-net Edited April 20, 2021 by Kurapica
ramzi2015 Posted April 20, 2021 Author Posted April 20, 2021 3 hours ago, Kurapica said: Probably you don't have admin rights. Try this : GetVolumeInformationA >> https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa Old school never fails. https://www.codeproject.com/Articles/16941/Get-Physical-HDD-Serial-Number-without-WMI C# : https://overcoder.net/q/2170341/как-использовать-ioctlscsiminiport-через-deviceiocontrol-из-c-net Thanks for your help.
xinzhang Posted September 19 Posted September 19 ManagementObjectSearcher can't get the correct searial number,sometime. To obtain the correct disk name and serial number, the best approach is to use CrystalDiskInfo(https://github.com/hiyohiyo/CrystalDiskInfo) . However, CrystalDiskInfois a Windows software written in C++. As a result, it cannot be directly used in one's own project. Therefore, I wrapped CrystalDiskInfo into a DLL. Now, other languages or Windows applications can also accurately distinguish the disk serial number with the help of CrystalDiskInfo. I have open-sourced this project on GitHub. If you are interested in it, you can check it out and use it. https://github.com/ftyszyx/CrystalDiskInfo_dll_lib 1
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