We can do this from Hyper-V (for example), but that does not allow this from GUI either.
The only way to change the boot sector and run some code on an Hyper-V VM is to use a VHD (not VHDX) with fixed size.
So, with Gui you can’t no longer create a VHD, so you need to do it in Powershell with (ex.):
New-VHD D:\VM\Test.VHD -SizeBytes 1GB -Fixed