Can you set hard disk serial number in hyper-v VM?

AdrianS

Ars Scholae Palatinae
1,326
Subscriptor
I have some software (written in-house) that I want to run in a Hyper-V VM, hosted on Win11 Pro.
The VM is running Win10 Pro.

The software licensing fails, because it can't see a hdd model or serial number (not volume serial).

I have not found a way to set the physical disk serial number for the vhd.
Both WMI and Powershell commands return a blank for serial number when run within the VM.

Also, the software is using IOCTL to get the disk info. That may be failing as well.

Web searches keep ending me up at dodgy games-crack sites, which install a service or driver to spoof the disk info, and I'd rather not go down that route. If I have to I will, but then I will be looking for something I can build (and sign) myself.

Suggestions welcome.
 

oikjn

Ars Scholae Palatinae
969
Subscriptor++
That really doesn't add up at all. Not sure why "in-house" software would have licensing at all and if it did, why you couldn't resolve it with the in-house programmers unless "in-house" just means "owned by the company" :flail:

Anyway, assuming you can't change the program, how about you try using a passthrough disk instead of a VHD? as I recall, those pass the actual disk to the system.
 

Andrewcw

Ars Legatus Legionis
18,129
Subscriptor
Trying to crack your own In-House application that uses copy protection? I mean what drugs were being used to decide an in-house program needed to be copy protected to hardware if it was mean to be used in-house.

Anyways is sounds like how the In-House applications that suddenly break at my office. Where it's usually they don't update a module because they didn't see a reason why to pay for support for a 3rd party module and the reason why it broke was some windows update or world wide way people use the protocol standard.
 

SplatMan_DK

Ars Tribunus Angusticlavius
7,794
Subscriptor++
If you need to actually set the serial number, then there is (to my knowledge) no official way of doing it. However, it's a decent bet that it will be a plaintext property in the file and by default is null or empty.

That means you could edit it with a file editor that has direct disk editing (sometimes incorrectly referred to as a "HEX editor" because bytes are edited by changing hexadecimal values representing the raw data).

There are several utilities which will allow you to do this, and any dev who ever touched a file stream will know how to operate it. The utility you select will also have a search function where you can input an existing serial number, to identify the correct address in the file. From there, you should be able to replace it. That may or may not be possible, since you report that the software can't even find the property. But in my own virtual disks I have serial numbers, so it's a property that's certainly supported.

Note that the serial number may actually be written several times, in different properties and locations. Standards have evolved over time, and redundant data is common and "by design" (in that nobody bothered to start from scratch).
 
Last edited:

AdrianS

Ars Scholae Palatinae
1,326
Subscriptor
To clarify a bit.
The (legacy) app was written in house, but its part of a machine we sell.

On startup, the app checks the HDD serial, and if it doesn't match the (encrypted) saved value, resets the license to unregistered and requests a key based (in part) on the HDD serial.
All this is not a problem, I have the key generator, I have the source code for everything.

I regularly restore customer backups to a spare laptop to examine them, and just have to re-license on startup.

The issue is that if I restore a customer backup to a hyper-v VM to examine it, the app reads a blank HDD serial on startup, and refuses to generate a valid key. I don't care what the serial is, but blank is an issue we've never seen in the wild, and it breaks the licensing.

I could hack the app, but it would be easier if I could set a HDD serial number for the VM like I can set a MAC address.

Since that seems to be impossible with hyper-v, I may look at other VMs.

If I get some spare time, I may use this problem as an excuse to knock up a minidriver filter for the VM that just fills in an arbitrary model and serial for that one IOCTL.
 

AdrianS

Ars Scholae Palatinae
1,326
Subscriptor
If you need to actually set the serial number, then there is (to my knowledge) no official way of doing it. However, it's a decent bet that it will be a plaintext property in the file and by default is null or empty.

That means you could edit it with a file editor that has direct disk editing (sometimes incorrectly referred to as a "HEX editor" because bytes are edited by changing hexadecimal values representing the raw data).

There are several utilities which will allow you to do this, and any dev who ever touched a file stream will know how to operate it. The utility you select will also have a search function where you can input an existing serial number, to identify the correct address in the file. From there, you should be able to replace it. That may or may not be possible, since you report that the software can't even find the property. But in my own virtual disks I have serial numbers, so it's a property that's certainly supported.

Note that the serial number may actually be written several times, in different properties and locations. Standards have evolved over time, and redundant data is common and "by design" (in that nobody bothered to start from scratch).
The issue is that every windows tool run inside the VM reports a blank HDD serial number.
Note this is not the volume serial number.

It's being provided by the VM, and being blank I can't go looking for it in the image file.
 

AdrianS

Ars Scholae Palatinae
1,326
Subscriptor
did you try the passthrough drive option? How about an iscsi mounted drive?
I tried a scsii drive, but the OS didn't want to boot from it.
A passthrough drive would probably work, but it's extra complication.

I posted here hoping someone would say "oh, it's option blah to set-vm", and the problem would be solved in a flash. Although that would have left me questioning my web search abilities.

I even tried the AI "search engines", and read a lot of MS docs.

Anyway, the short answer appears to be:

No, there's no recognised way of setting the drive serial number of a virtual hard disk in a Hyper-V gen2 VM, although there may be ways of spoofing it.
 

SplatMan_DK

Ars Tribunus Angusticlavius
7,794
Subscriptor++
The issue is that every windows tool run inside the VM reports a blank HDD serial number.
Note this is not the volume serial number.

It's being provided by the VM, and being blank I can't go looking for it in the image file.
But couldn't you find the correct property or address looking at a physical disk? Or by making a P2V conversion? (Physical machine to Virtual - there are software agents for that, including for HyperV).
 

oikjn

Ars Scholae Palatinae
969
Subscriptor++
I tried a scsii drive,
iscsi is not the same as scsi. passthough or iscsi should work, but yes it is extra work. The alternative is have your internal people patch the software for you to allow a null valve to generate a key for you. or if that is too much work... guess you get to use a physical machine
 

Paladin

Ars Legatus Legionis
32,552
Subscriptor
I would use that situation as a lever to get the developers to rethink how they do the key generation/verification. There are other hardware IDs in a system that are much more reliable than a hard drive serial number. You must go through problems every time a drive starts to fail. You could have them use several factors and if any of them show up as null, you simply factor that into the resulting hash.
 

SplatMan_DK

Ars Tribunus Angusticlavius
7,794
Subscriptor++
I would use that situation as a lever to get the developers to rethink how they do the key generation/verification. There are other hardware IDs in a system that are much more reliable than a hard drive serial number. You must go through problems every time a drive starts to fail. You could have them use several factors and if any of them show up as null, you simply factor that into the resulting hash.
If you're reworking it anyway, just use the proper API call for exactly this purpose.

 

AdrianS

Ars Scholae Palatinae
1,326
Subscriptor
iscsi is not the same as scsi. passthough or iscsi should work, but yes it is extra work. The alternative is have your internal people patch the software for you to allow a null valve to generate a key for you. or if that is too much work... guess you get to use a physical machine

Patching the current software won't help for the most common case, which is replicating a customer system using their backup.

We could change the verification process for future releases of the software, but it would be a low priority. What we have works.

If the customer has a disk failure they tend to contact us anyway, and re-licensing takes less than a minute.
 

AdrianS

Ars Scholae Palatinae
1,326
Subscriptor
If you're reworking it anyway, just use the proper API call for exactly this purpose.


That would be the best way to go, if we updated the license code. There are lots of things higher on the priority list - this issue is more a quirk of the VM software.

This product has been around a very long time by software standards, and getting the HDD serial number has worked since Windows XP.
 

SplatMan_DK

Ars Tribunus Angusticlavius
7,794
Subscriptor++
That would be the best way to go, if we updated the license code. There are lots of things higher on the priority list - this issue is more a quirk of the VM software.

This product has been around a very long time by software standards, and getting the HDD serial number has worked since Windows XP.

Try VMware then. And be sure to use an IDE disk. When using virtual SCSI disks the serial number property is empty. (I just checked).