Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
in order to get the hard disk's serial.
How can I implement this in b4j. I understand that perhaps it's just a call, yet, didn't check how to do it.
There is no simple cross platform way to get the serial number. On windows you can use jShell to run the "vol" command and parse the result. You might need to run it with cmd /c vol.
rwblinn, I altered your script a bit, and now I have this, which supposedly return the physical drive's serial. Tried it, I guess it works, so you may want to add it to your scripts' library
B4X:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_physicalmedia",,48)
For Each objItem in colItems
s = s & "SerialNumber: " & objItem.SerialNumber & vbcrlf
s = s & "Model: " & objItem.Model
Next
wscript.echo s
There isn't any perfectly reliable way to get the hardware serial number even if you just consider Windows. WMI uses a bunch of "by guess and by golly" techniques to try to extract it from various devices but even so it sometimes fails. The low-level code required varies by drive manufacturer, drive model, and by adapter type. And if the WMI service has been disabled on a given machine you're stuck.
Thanks for showing using Win32_physicalmedia ... but ... agree with dilettante = results are depending on manufacturer, windows version, adapter. All in all not reliable.