Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
Quote:
in vista the return is in ascii
but in widows 7 the return is a hex string
The code for BIOS & Motherboard Serial is also in Roy sample (thread #15) but not in Vista and Windows 7 due to the reason like HDD SN that you show me above. As I am crazy :) so I thing if you did it already then share (just copy & paste here) to me so that I don't have to play it myself (OK, I 'll do it myself in both Vista and W7 like you did :)).
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
the returns of my test in windows 7 home premium for baseboard, were standard strings, no decoding required
also the return for hdd serial as administrator was already decoded, i have no idea why there should be a difference in the return for different users
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
When I debug in Windows XP:
Code:
s = " MPC312Y3GDHJVE" --> Len(s) = 20
vb Code:
ElseIf Len(s) = 20 Then
For i = 1 To Len(s) Step 2 ' vista
sn = sn & Mid(s, i + 1, 1) & Mid(s, i, 1)
Next
Because Len(s) = 20 then sn was decoded and return: In this Windows XP, the API code run and it return: "MPC312Y3GDHJVE"
Why len(s) = 20 is the clue for Vista? (in vista the return is in ascii)
Why len(s) > 20 then Windows 7? I tested in Vista and return len(s) >20 also
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
you are correct, and may have to try some other method to decide if the string is returned directly as in xp or not, this seemed to work when i was testing, but i only tried on one machine for windows 7 and 2 for vista, i have never tested as a limited user in xp, to see how it is returned, i might do that now
with brief testing wmi does not appear to return the hdd serial number in XP as limited user
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
Can you translate the Java script to VB6?
Quote:
Vista with UAC returns correct S/N, but for some reason in a raw memory dump (hex encoded) format.
This simple script (in java script because of convenience - may rewrite this to C if you like) demonstrates how to decode the latter S/N:
Code:
<html><script language=JavaScript>
function dehex(str){
var res = "";
for(i = 0; i < str.length; i++){
if((i % 2) == 0){
res = res + "%";
}
res = res + str.charAt(i);
}
return unescape(res);
}
function BEW2LEW(str){ //Big endian word to little endian word
var res = "";
for(i = 0; i<str.length; i+=2){
res += str.charAt(i+1) + str.charAt(i);
}
return res;
}
alert(BEW2LEW(dehex("30535531324a5930333632303537202020202020")));
</script></html>
N.B. This seems to be bug in Vista - consider reporting it to MS.
And BTW, it wasn't very hard to guess it, provided you observe that hex code for space is 0x20, after "de-hexing" the s/n i observed it is simply mangled (little/big endian change), so wrote additional function to correct it, and it worked :), hopefully :). I'm glad if I can help someone :).
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
It will be something like this: :wave:
Code:
Private Function dehex(ByVal str As String) As String
Dim res As String
Dim i As Integer
res = ""
For i = 0 To Len(str)
If i Mod 2 = 0 Then
res = res & "%"
End If
res = res & Mid(str, i, 1)
Next i
dehex = unescape(res) '~~~> don't know unescape
End Function
Private Function BEW2LEW(ByVal str As String) As String
Dim res As String
Dim i As Integer
res = ""
i = 0
While i < Len(str)
res = res & Mid(str, i + 1, 1) & Mid(str, i, 1)
i = i + 2
Wend
BEW2LEW = res
End Function
(Not tested). unescape(res) isn't mentioned in your code... So, I don't know what it is used for.... !
1 Attachment(s)
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
Here is the code
vb Code:
For Each objItem In colItems
s = objItem.SerialNumber
If IsHex(s) Then
GetHardDriveSerial = Trim$(BEW2LEW(dehex(s)))
Else
GetHardDriveSerial = Trim$(s)
End If
Exit For
Next
vb Code:
Function dehex(Data As String) As String
On Error Resume Next
Dim iCount As Double
For iCount = 1 To Len(Data) Step 2
dehex = dehex & Chr$(Val("&H" & Mid$(Data, iCount, 2)))
Next iCount
End Function
Function BEW2LEW(ByVal str As String) As String
Dim res As String
Dim i As Integer
res = ""
i = 1
While i < Len(str)
res = res & Mid(str, i + 1, 1) & Mid(str, i, 1)
i = i + 2
Wend
BEW2LEW = res
End Function
Function IsHex(ByVal value As String) As Boolean
On Error Resume Next
Dim i As Integer
IsHex = True
If Len(value) = 0 Then
IsHex = False
Exit Function
End If
For i = 1 To Len(value)
If InStr("0123456789ABCDEF", UCase$(Mid$(value, i, 1))) = 0 Then
IsHex = False
Exit Function
End If
Next
End Function
See attachment for the full code
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc
Re: How can know Manufacture Hardware ID (Serial Number) of Disk or MotherBord etc