B4J Question getVolumeInformation

mc73

Well-Known Member
Licensed User
Longtime User
In vb I can
B4X:
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.
 

mc73

Well-Known Member
Licensed User
Longtime User
Thank you Erel.
Let me, though, apologise for the thread's title and given code.
What I am really after is the physical drive's serial number.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Thank you very much! Still, does it return the physical drive's serial? I'll test it anyway, thank you again!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Hi,

another alternative is using jShell and Windows Script Host.
Pls look here (http://www.rwblinn.de/b4j/b4jhowto/examples/b4jhowtoshell.zip) which is one of my B4J HOWTOs example projects.
Select Menu WSH > Select Script > getserialnr.vbs.

Hi again,

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
 
Upvote 0

dilettante

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks for showing using Win32_physicalmedia ... but ... agree with dilettante = results are depending on manufacturer, windows version, adapter. All in all not reliable.
 
Upvote 0
Top