top of page
avroomjucucor

Get Hardisk Serial Number In Vb.net



What is a hard drive serial number? Refers to the identity as a hard drive, but sometimes it is found that the computer hard drive serial number of the colleague is duplicated. So the hard drive identification we can try to test the ID, this how to get the following explanation.




Get Hardisk Serial Number In Vb.net



you mean no hdd serial number show? if your hdd connect with primary master then it automatically show when you run this project. in my pc it show and it show the hdd serial number what is write on body of hdd. i don't understand what problem with you.


According the documentation on MSDN, Win32_Volume - Serial number is just the serial number of the Volume whereas the Win32_DiskDrive - Serial number is the manufacturer serial number of the disk drive. So the question is which serial number do you want?


This doesn't really doesn't address the underlying issue shown in the question: WMI is returning acorrupt serial number. Mark is getting the serial number encoded as hexadecimal digit pairs which represent the ASCII characters of the actual serial number. This does not match the documented behavior.


Not a bug. It is the way the vendor inserts the serial number into the device. The serial number has been inserted as a hex string. Thisis also the way SNMP serial numvers are meant to work. WMI and CIM make no attempt to convert this data. That is up to the end user. YOu must know how the vendor inserts this.


Thanks, your reply is actually very helpful. I think the key part of my post you may have missed was where I mention theintermittent results we see. Same vendor, same drive, but the serial number comes back in different forms for thesame WMI property. That is what has led us to conclude that WMI isn't merely passing that data back as-is [we would actually prefer that]. We're just not sure if it's attempting to fix the values but after a delay, or if it's switching which driver calls it uses, or if there are just race conditions inherent in the design of the system.


Anyway, for now let's just talk about the prevalence of hexadecimal format, and the predictable [non-intermittent] format changes I've seen. Here's a simple query run on my Windows 7 system. The blue window is running as an elevated account, the black window is running as a normal user account. Note that none of the drive serial numbers are in hexadecimal. Also note that the query returns the values in different forms [big-endian or little-endian ASCII] depending on which user does the query. To make things more unpredictable, the third drive's serial number remains the same [it's a CD drive], so we can't make reliable assumptions about how to "fix" the serial numbers. This particular behavior is all new with Vista; our code had worked as expected on Windows XP.


jrv, I hate to break it to you, but HD serial numbers have never been represented as hex-encoded ASCII strings. It's just the way Windows shows them. Why would they be hex? Take a unit from your shelf or ask someone to hand it over to you and check the S/N imprinted on the label. Is it hex-encoded? I'm sure it's not. And so it is no t flashed as such in device's ROM. Grab a live CD with Linux, if you want, launch it and run `hdparm -I /dev/ grep Serial' from terminal. I did that for my SSD. Here's what the result read: OCZ-E84E5605IJTH4698 and here's what Windows gives:434f2d5a38454534363535304a49485436343839 ...yeah.Of course, you might think that Linux processes the original data to provide that clean string. It (almost) does not. Want a proof? Thankfully, unlike with Windows, we can check Linux source code,here is the link to ATA driver core, check it out.The only processing that takes place on Linux is swapping every two bytes with each other. This is an important part because it explains why hex-pairs are un-flipped on Windows so please bare with me. Drives send serial number and other information in response to ATAPI command IDENTIFY DEVICE. The response is being sent in 16-bit words. This doesn't make sense today when most drives use serial communication, but it works that way to maintain backwards compatibility with IDE (PATA drives) which were indeed using 16-bit data bus. ATAPI specification enforces the drive to encode all ASCII strings on 2-byte words using big-endian notation, so when you see such chunk of memory on little-endian machine (every Windows is LE, I think) it appears that subsequent pairs of bytes have been flipped.Now what Windows does apparently, is to take the memory as it was received from the device and encode it to hex. I don't know the reasoning behind it. This method probably made some sense in the old days and was preserved until today for compatibility reasons. I wouldn't have troubles with it if the results were consistent across all versions of Windows but, clearly, they are not.When you run the following command:


on Windows 7 x64 (winver: 6.1, build 7601) using admin account, the serial number will be hex-encoded and flipped. If you start powershell with elevated permissions, it will be correct (ASCII and not-flipped). Mind you, I'm talking here about the same account that has admin privileges. The only difference is that you start powershell a) normally, b) using "run as administrator". Further more, Model property returned by the query above is empty regardless of what method you use.


I haven't encountered this problem with Win32_DiskDrive, though. Limited users, admins, elevated or not, it always returns SerialNumber in hex-encoded and flipped form. I guess that's something. But the property isn't available on Windows XP so you have to diverge your script depending on host OS.Here's another quirk, BTW. On Windows 7 Win32_DiskDrive.Model property is suffixed with " device". So if your drive model is "OCZ-AGILITY3" (as returned by ATAPI), the Model property will be "OCZ-AGILITY3 ATA device". Windows XP, however, reports it without extras. Lovely, isn't it?So btj-agilent is correct all the way:a) Windows returns drive serial number, which is not a real serial number,b) the number can differ depending on the OS (which was a topic of a couple of bug reports on Microsoft Connect).The flipped S/N are caused by buggy WMI, not encoding problems. (BTW, jrv, how on earth can the difference between ANSI and Unicode encoding be responsible for swapping letters in string? Care to explain?)To the OP and anyone who wants to use WMI to get HD properties:If you can, avoid WMI when accessing those information. Especially if some vital functionality depends on it. WMI just appears to be broken and you cannot depend on it giving you concise results. Use IOCTLs in an executable tool and wrap it with your script instead. If you have to use PowerShell all the way (for example when you need to run the command remotely on domain nodes) take into account the points above. The subject of WMI returning bad serial numbers for accounts with different access rights was reported to Microsoft in 2010. Apparently it hasn't been fully resolved since.


-- -------------------------------- "For every action, there is an equal and opposite criticism." Wed, 18 Jun 1902 08:00:00 GMT Pete#2 / 5 Serial Number of CD-R Disk This will get the serial number... -helper.com/HowTo/serialno.zip Keep everyone posted on your findings! Peter Quote:> I notice whenever I place a blank CD-R into my drive, Explorer > shows some kind of serial number. Is this written onto the CD-R > as they are purchased? Does anyone have a way of reading the > number from VB or a utility? I was wondering about the idea of > using the serial number, if it's there, to write a hidden file > with the encrypted serial number in it. Then, during > installation, you could compare the two to see if the CD is > original or not. Ideas? > -- > -------------------------------- > "For every action, there is an equal and opposite criticism." computer_2(); Wed, 18 Jun 1902 08:00:00 GMT Johan Bechthu#3 / 5 Serial Number of CD-R Disk Signet, I use the HP CD-Writer+ 9100 and it also assigns a serial number to a new CD-Rom. It seems to me that the assigned number the current date and time presents in the format "yymmdd_hhmm" Look carefully at the number, maybe it's the same with you. Johan. I notice whenever I place a blank CD-R into my drive, Explorer shows some kind of serial number. Is this written onto the CD-R as they are purchased? Does anyone have a way of reading the number from VB or a utility? I was wondering about the idea of using the serial number, if it's there, to write a hidden file with the encrypted serial number in it. Then, during installation, you could compare the two to see if the CD is original or not. Ideas? -- -------------------------------- "For every action, there is an equal and opposite criticism." Wed, 18 Jun 1902 08:00:00 GMT St Augustine's Colleg#4 / 5 Serial Number of CD-R Disk I think you'll find that the 'serial number' you describe is actually the drive label. The CD serial no is assigned at the time the CD is actually made (as far as I know). Quote:> Signet, > I use the HP CD-Writer+ 9100 and it also assigns a serial number to a new > CD-Rom. It seems to me that the assigned number the current date and time > presents in the format "yymmdd_hhmm" > Look carefully at the number, maybe it's the same with you. > Johan. > I notice whenever I place a blank CD-R into my drive, Explorer > shows some kind of serial number. Is this written onto the CD-R > as they are purchased? Does anyone have a way of reading the > number from VB or a utility? I was wondering about the idea of > using the serial number, if it's there, to write a hidden file > with the encrypted serial number in it. Then, during > installation, you could compare the two to see if the CD is > original or not. Ideas? > > -- > -------------------------------- > "For every action, there is an equal and opposite criticism." > > > > Wed, 18 Jun 1902 08:00:00 GMT Rick Rothstei#5 / 5 Serial Number of CD-R Disk Depending on which one Signet wants: GET VOLUME NAME =========================== If you simply want the VolumeName, you can do this: VolumeName = Dir("d:", vbVolume) which yields the name for drive "d:" -- substitute the drive letter you are interested in for the other drives. GET SERIAL NUMBER =========================== Try using this declaration and function (you can pass the drive letter in as a letter by itself, a letter followed by a colon or a letter followed by a colon followed by a backslash): Private Declare Function GetVolumeInformation _ Lib "kernel32.dll" _ Alias "GetVolumeInformationA" _ (ByVal lpRootPathName As String, _ ByVal lpVolumeNameBuffer As String, _ ByVal nVolumeNameSize As Integer, _ lpVolumeSerialNumber As Long, _ lpMaximumComponentLength As Long, _ lpFileSystemFlags As Long, _ ByVal lpFileSystemNameBuffer As String, _ ByVal nFileSystemNameSize As Long) As Long Function GetSerialNumber(DriveLetter As String) As String Dim SerialNum As Long Dim VolNameBuf As String Dim FileSysNameBuf As String Select Case Len(DriveLetter) Case 1 If DriveLetter Like "[a-z]" Then DriveLetter = Left$(DriveLetter, 1) & ":\" Else GetSerialNumber = "Error - Bad drive designation" End If Case 2 If LCase(DriveLetter) Like "[a-z]:" Then DriveLetter = DriveLetter & "\" Else GetSerialNumber = "Error - Bad drive designation" End If Case 3 If LCase(DriveLetter) Like "[!a-z]:\" Then GetSerialNumber = "Error - Bad drive designation" End If Case Else GetSerialNumber = "Error - Bad drive designation" End Select If Len(GetSerialNumber) = 0 Then VolNameBuf = String$(255, Chr$(0)) FileSysNameBuf = String$(255, Chr$(0)) GetVolumeInformation DriveLetter, VolNameBuf, _ Len(VolNameBuf), SerialNum, 0, 0, _ FileSysNameBuf, Len(FileSysNameBuf) GetSerialNumber = Right$("00000000" & Hex$(SerialNum), 8) End If End Function Rick Quote:> I think you'll find that the 'serial number' you describe is actually the > drive label. > The CD serial no is assigned at the time the CD is actually made (as far as > I know). > > Signet, > > I use the HP CD-Writer+ 9100 and it also assigns a serial number to a new > > CD-Rom. It seems to me that the assigned number the current date and time > > presents in the format "yymmdd_hhmm" > > Look carefully at the number, maybe it's the same with you. > > Johan. > > I notice whenever I place a blank CD-R into my drive, Explorer > > shows some kind of serial number. Is this written onto the CD-R > > as they are purchased? Does anyone have a way of reading the > > number from VB or a utility? I was wondering about the idea of > > using the serial number, if it's there, to write a hidden file > > with the encrypted serial number in it. Then, during > > installation, you could compare the two to see if the CD is > > original or not. Ideas? > > > > -- > > -------------------------------- > > "For every action, there is an equal and opposite criticism." > > > > > > > > Wed, 18 Jun 1902 08:00:00 GMT Page 1 of 1 [ 5 post ] Relevant Pages 1. Disk Serial Number Problems 2ff7e9595c


0 views0 comments

Recent Posts

See All

Baixar livros inglês para iniciantes grátis

Скачать книги английский для начинающих бесплатно: как и где найти лучшие ресурсы Вы хотите изучать английский язык, но не знаете, с чего...

Comments


bottom of page