In both the above cases MS support should assist with any issues since a retail code is re-usable. Remember you will need to install the version of windows that the code is valid for ie if the code is for win7, you can't install and authenticate windows 10 off the bat and need to go through the motions of upgrading AFTER authentication. I recently used a win 7 code but it's getting difficult since NVMEs aren't recognised and they've removed the win 7 auth checks when it went out of support.
If it's OEM and/or you have no code, you may be out of luck and need to purchase a new one. Could still be worth a call but you're relying on MS goodwill.