Hannes,
Well, it's nice of you to say so but I think the script is not [yet] worthwhile in a running system that needs its external disk letters restored to those first set up.
What it needs is an intervention that seeks a list of those drive letters not to interfere with so that all others can be removed prior to the restoration [because prior removal is required to avoid attempting to set multiple drive letters for the same hardware].
That intervention is what I had hoped to avoid but cannot.
Only the user can know which drive letters to avoid removing-restoring in order to avoid disrupting Windows
For example, in
C:\ D:\ E:\ F:\ K:\ M:\ T:\ V:\
I know that I must not remove or change C:\ D:\ E:\ M:\ because they are significant within Windows:-
C:\ is my OS drive
D:\ & E:\ contain user folders
M:\ is the location of my [MS] Maps data files. Windows gets really shirty about this being changed and, if it is, I have to reset the drive letter to D:\ in Settings-Maps, download the smallest Map I can find to get Windows to recognise D:\ again for the job and then restore my D:\ drive image with the whole set of MS Maps in order to get back to normal working.
I don't care about V:\ even though it is on an internal disk.
Nobody but me knows what must be avoided.
I can generate the list CDEFKMTV during the backup procedure and present it to the user early in the restoration procedure [probably in a vbs InputBox] for the user to remove or even add entries.
I had hoped not to need to do this but, as I say, it is unavoidable because nobody else knows the significance of any particular drive letter. Even C:\ has been known to vary [it's almost a decade since I've seen Windows 10 install itself to the drive letter F:\ and the very few reports by others also indicates its rarity - I wish now that I'd made a screenshot of it].
Incidentally, I use a very slightly different self-elevation method and one is pretty much as good as any other but I always combine mine with an ampersand check because no self-elevation method I have tried can work correctly with the batch file in a path that contains an ampersand.
Set "ThisPath=%~dp0"
If Not "%ThisPath:&=%"=="%ThisPath%" ((cls) & (Title ERROR) & (Echo This procedure cannot be used with the batch file in a path containing an ampersand. Move the batch file to a different location before running it again.) & (Pause) & (GoTo Endex))
reg query "HKU\S-1-5-19" >nul ||(PowerShell start """%~dpnx0""" -verb RunAs & Exit /B)
:Endex
pause at Endex during testing
If there's an ampersand in the path, the command
PowerShell start """%~dpnx0""" -verb RunAs
fails. I've tried the variations I would normally think of for coping with & but have not found a solution.
All the best,
Denis