I had to replace a hard drive in a Packard Bell PC which they sent through the post with a return packet post paid.
The new hard drive was bare and not formatted so did not have any O'S on.
I was lucky that my hard drive was very noisy hence the replacement (on warranty).
Before I took it out of the PC I used Acronis to make a copy of the hard drive and then restored it to the new hard drive, that way every thing on the old hard drive was saved to the new one.
You may have a recovery disk with your machine or you had to make your own and that would put your operating system back onto the new hard drive exactly as it was one the PC was first used.
Most PC come with either a recovery disk or instructions on how to make one. They used to come with a Windows disk years ago.