Import drive letters for use after reinstall?


What I was asking is if you hadn't connected the S drive first would the first drive you connected get it's own drive letter or would it automatically be assigned the drive letter S
I just repeated the experiment.
I deleted the S entry I had put in before so I was starting from scratch.
I used the .reg file to add the desired S entry.
I connected a disk it had not seen before and it was assigned F:\, the next letter in turn.
I connected the S disk and it was assigned S:\.


All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
I'll have to make note of this for "bag of tricks", although I have to admit I'm not really sure if I will ever use it
Hannes,

I felt the same until I realised it could be used to save the current configuration.

I have exported the Registry Key and deleted all the non-"\\DosDevices\\ entries so I have a restoration file [it is so tedious working with that exported key]. I have also deleted all entries related to internal disks.
I do use the same assignments on all my computers so the .reg can be used on them all.

I'm having a stab at a script for extracting the relevant values and writing them into a Reg Add script for restoration.
I have the feeling that it won't work.
And it's late and I'm tired.


All the best,
Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
So you'll get something in the pattern of my post #32.
OK, thank you very much!
 

My Computer

System One

  • OS
    Win 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo IdeaPad 3 17ABA7 Laptop - Type 82RQ (Lenovo IdeaPad 3 82RQ003EGE)
    Memory
    16 GB
OK, thank you very much!
Do delete all lines related to disks other than those external disks you asked about.
The file you create will have an entry for C:\ but Windows creates that for the particular hardware of that computer.
In my own file, I have deleted the lines for C:\, D:\ & M:\ because these are always disks / partitions on the particular computer concerned. I accept that I'll manually set up D:\ & M:\ after a Windows installation.


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
That's good point, so I would also delete some of those lines, I have two or three partitions on internal drive C:, yes, maybe better to assign the letters manually.

And I would do the registry mess immediately after an installation, if I completely would destroy the registry I just could install Win again. Respectively I would make a backup of the reg before.

Many thanks!
 

My Computer

System One

  • OS
    Win 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo IdeaPad 3 17ABA7 Laptop - Type 82RQ (Lenovo IdeaPad 3 82RQ003EGE)
    Memory
    16 GB
Yes, I expected it would be fine. I used to back up the key in winpe then restore it after macrium had screwed them up. I dont bother with that in winpe now, I just reset the shortcuts instead.
 

My Computers

System One System Two

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
This script writes a batch file that can be run, with Admin approval, to restore the current external disk drive letter assignments.
I selected my approach to the job for these reasons
- the hardware used for external disks will change from time to time so the job will need to be done more than once, and
- running this script will be less work than editing an export of that Registry key, and
- using Reg Add commands is less work than running ["merging"] an exported Registry key.
The backing up script runs without any need for elevation.
The output file RestoreAssignedDrives.bat needs Admin approval to run because it writes to HKLM.
BackupAssignedDriveLetters.bat [attached]
:: This script backs up external drive letter assignments into a script file for writing them back into the Registry
:: My list of assignments to skip backing up for, the lines beginning If "%ThisLine:~0,13%", account for all my internal drives because it would be inappropriate to restore their drive letters to different computers [as I intend to do].
:: The output file is re-written every time this script is run.
:: Written by Denis, Try3
:: This script was originally posted in www.elevenforum.com/t/import-drive-letters-for-use-after-reinstall.22267

:: Alter the prompt to help see commands and their responses clearly
prompt $g
:: Some people like adding an @echo off command but I don't.
:: - The script does not take so long to run that I would ever feel any benefit from the time saved in execution by using @echo off.
:: - I run scripts such as these minimised so I would not benefit from hiding anything
:: - I would have to cancel the @echo off & run that modified version of the script if I needed to debug the script
:: - As it stands, if I wanted to debug then I would re-add the leading :: from the final line of this script [which I've left in for the time being but will remove when testing is complete]

:JustGetOnWithIt
:: Set up output
:: I will use a protected script folder because the output is an active object
:: I have tested that the output path can include spaces and special characters such as ampersands.
Set "OutputFolder=%~dp0"
:: Remove trailing \ from OutputFolder [swapping around values during testing can often lead me to mistakes in this regard]
If "%OutputFolder:~-1%"=="\" Set OutputFolder=%OutputFolder:~0,-1%
Set "OutputFile=%OutputFolder%\RestoreAssignedDrives.bat"

:: Write the preamble in the output file
echo ::This script restores the backed up drive letter assignments for external disks>"%OutputFile%"
echo ::This script must be run as Admin because it writes entries to HKLM>>"%OutputFile%"
echo :: Written by Denis, Try3 TenForums, ElevenForum, TwelveForums>>"%OutputFile%"
echo :: The parent script was originally posted in www.elevenforum.com/t/import-drive-letters-for-use-after-reinstall.22267>>"%OutputFile%"

:: Read each line of the Registry Key
For /F "tokens=*" %%A in ('Reg Query "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices" ') Do Call :ProcessEachLine "%%A"
GoTo Endex

:ProcessEachLine
:: This subroutine reads each line of the Registry Key
Set "ThisLine=%~1"
:: Escape if a blank line has been passed [I have not checked that that cannot happen and it's easyto assume it can]
If "FF%ThisLine%FF"=="FFFF" GoTo :EOF
:: Escape for all non-relevant lines in this huge Registry Key
If Not "%ThisLine:~0,12%"=="\DosDevices\" GoTo :EOF
::::: Put in escapes for internal drives C D E F M
::::: My method of escaping F:\ for the sake of the one computer that has an internal disk F:\ means that I will not backup any F:\ drive letter assignments from any computer but that's fine as I never use any
::::: If I backed them up I would have to insert a ComputerName-dependent escape into the restoration script anyway so I might as well keep it simple
If "%ThisLine:~0,13%"=="\DosDevices\C" GoTo :EOF
If "%ThisLine:~0,13%"=="\DosDevices\D" GoTo :EOF
If "%ThisLine:~0,13%"=="\DosDevices\E" GoTo :EOF
If "%ThisLine:~0,13%"=="\DosDevices\F" GoTo :EOF
If "%ThisLine:~0,13%"=="\DosDevices\M" GoTo :EOF

:: Write each relevant line, each drive letter assignemnt to be restored, into the output file
:: Lines extracted from the Registry key are in the pattern \DosDevices\S: REG_BINARY 444D494F3A49443A6C973A17EA6A53469D66AAAC5B339B57
:: Required syntax for the Reg Add command that does the restoration Reg Add HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices /v \DosDevices\S: /t REG_BINARY /d 444D494F3A49443A6C973A17EA6A53469D66AAAC5B339B57
echo Reg Add HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices /v %ThisLine:~0,14% /t REG_BINARY /d %ThisLine:~31%>>"%OutputFile%"

GoTo :EOF

:Endex
:: Pause at end during testing


A shortened example of its output, RestoreAssignedDrives.bat, is
::This script restores the backed up drive letter assignments for external disks
::This script must be run as Admin because it writes entries to HKLM
:: Written by Denis, Try3 TenForums, ElevenForum, TwelveForums
:: The parent script was originally posted in www.elevenforum.com/t/import-drive-letters-for-use-after-reinstall.22267
Reg Add HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices /v \DosDevices\S: /t REG_BINARY /d 444D494F3A49443A6C973A17EA6A53469D66AAAC5B339B57

I have tested
BackupAssignedDriveLetters.bat
RestoreAssignedDrives.bat

and they work.

I had intended to include a self-elevating code block in RestoreAssignedDrives.bat but am having trouble getting it to work [I last worked on this topic four years ago and it's difficult getting back into the right frame of mind to understand the notes I kept about it]. My problem is writing that code block into the output file in a manner that survives elevation.


Denis
 

Attachments

  • BackupAssignedDriveLetters.bat
    3.9 KB · Views: 2
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
I just repeated the experiment.
I deleted the S entry I had put in before so I was starting from scratch.
I used the .reg file to add the desired S entry.
I connected a disk it had not seen before and it was assigned F:\, the next letter in turn.
I connected the S disk and it was assigned S:\.


All the best,
Denis
Thanks for doing the test to see if it actually does keep the drive letter assigned to the original drive or not. I do have a few USB drives I always want to be the same drive letter. The drives I use for my system images and the drives I use for my media content as an example. Knowing this reg hack may come in handy for me when I replace one or more of my computers in the future.
 

My Computers

System One System Two

  • OS
    Windows 11 Canary Channel
    Computer type
    PC/Desktop
    Manufacturer/Model
    PowerSpec B746
    CPU
    Intel Core i7-10700K
    Motherboard
    ASRock Z490 Phantom Gaming 4/ax
    Memory
    16GB (8GB PC4-19200 DDR4 SDRAM x2)
    Graphics Card(s)
    NVIDIA GeForce GTX 1050 TI
    Sound Card
    Realtek Audio
    Monitor(s) Displays
    Samsung SAM0A87 Samsung SAM0D32
    Screen Resolution
    1920 x 1080
    Hard Drives
    NVMe WDC WDS100T2B0C-00PXH0 1TB
    Samsung SSD 860 EVO 1TB
    PSU
    750 Watts (62.5A)
    Case
    PowerSpec/Lian Li ATX 205
    Keyboard
    Logitech K270
    Mouse
    Logitech M185
    Browser
    Microsoft Edge and Firefox
    Antivirus
    ESET Internet Security
  • Operating System
    Windows 11 Canary Channel
    Computer type
    PC/Desktop
    Manufacturer/Model
    PowerSpec G156
    CPU
    Intel Core i5-8400 CPU @ 2.80GHz
    Motherboard
    AsusTeK Prime B360M-S
    Memory
    16 MB DDR 4-2666
    Monitor(s) Displays
    23" Speptre HDMI 75Hz
    Screen Resolution
    1920x1080
    Hard Drives
    Samsung 970 EVO 500GB NVMe
    Mouse
    Logitek M185
    Keyboard
    Logitek K270
    Browser
    Firefox, Edge and Edge Canary
    Antivirus
    Windows Defender
2024strugglecontinueswithharddrives.png

I have a lot of data and I move a lot of data from drive to drive. Ever since I installed Windows 11 on my PC I've had trouble keeping all my drives in order. Admittedly, I have a number of hard drives but before Windows 11 was installed on this unit they kept themselves in alphabetical order in Disk Management and stayed that way. Even Windows 7 kept them in their proper alphabetical order. My friend thinks I'm being OCD about this but it does help to read what's what quickly and efficiently when transferring data. Order isn't necessarily a bad thing, especially when one is using a considerable number of drives.
 

My Computer

System One

  • OS
    WIN 11, WIN 10, WIN 8.1, WIN 7 U, WIN 7 PRO, WIN 7 HOME (32 Bit), LINUX MINT
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY, ASUS, and DELL
    CPU
    Intel i7 6900K (octocore) / AMD 3800X (8 core)
    Motherboard
    ASUS X99E-WS USB 3.1
    Memory
    128 GB CORSAIR DOMINATOR PLATINUM (B DIE)
    Graphics Card(s)
    NVIDIA 1070
    Sound Card
    Crystal Sound (onboard)
    Monitor(s) Displays
    single Samsung 30" 4K and 8" aux monitor
    Screen Resolution
    4K and something equally attrocious
    Hard Drives
    A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W

    Ports X, Y, and Z are reserved for USB access and removable drives.

    Drive types consist of the following: Various mechanical hard drives bearing the brand names, Seagate, Toshiba, and Western Digital. Various NVMe drives bearing the brand names Kingston, Intel, Silicon Power, Crucial, Western Digital, and Team Group. Various SATA SSDs bearing various different brand names.

    RAID arrays included:

    LSI RAID 10 (WD Velociraptors) 1115.72 GB
    LSI RAID 10 (WD SSDS) 463.80 GB

    INTEL RAID 0 (KINGSTON HYPER X) System 447.14 GB
    INTEL RAID 1 TOSHIBA ENTERPRIZE class Data 2794.52 GB
    INTEL RAID 1 SEAGATE HYBRID 931.51 GB
    PSU
    SEVERAL. I prefer my Corsair Platinum HX1000i but I also like EVGA power supplies
    Case
    ThermalTake Level 10 GT (among others)
    Cooling
    Noctua is my favorite and I use it in my main. I also own various other coolers. Not a fan of liquid cooling.
    Keyboard
    all kinds.
    Mouse
    all kinds
    Internet Speed
    360 mbps - 1 gbps (depending)
    Browser
    FIREFOX
    Antivirus
    KASPERSKY (no apologies)
    Other Info
    I own too many laptops: A Dell touch screen with Windows 11 and 6 others (not counting the other four laptops I bought for this household.) Being a PC builder I own many desktop PCs as well. I am a father of five providing PCs, laptops, and tablets for all my family, most of which I have modified, rebuilt, or simply built from scratch. I do not own a cell phone, never have, never will.
I had intended to include a self-elevating code block in RestoreAssignedDrives.bat but am having trouble getting it to work
I solved my problem with this and can now include self-elevation in the output script RestoreAssignedDrives.bat [which needs elevation because it writes to HKLM].
I've also added self-elevation in BackupAssignedDriveLetters.bat because I am going to write the output file, RestoreAssignedDrives.bat, in a protected folder [as I do for all my scripts].


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
The more I consider my script, the more problems I find.
- As a tool to use on a new installation, it seems fine.
- As a tool to use to restore a configuration to an existing installation, it has serious shortcomings in that a saved configuration with a specific disk as H:\ could be restored after I had changed setup & made that disk, say, U:\. So my tool could result in that disk being assigned as both H:\ & U:\ which would cause unknown problems. I think the restoration process would have to start by removing all existing external disk drive letter assignments.

I can see how I might handle that.
But then I might identify further shortcomings.
I don't know if the game is worth the candle.


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
one possibilty could be could use a similar method to delete the dosdevices except for the os .Your processeachline could escape the os entry and reg delete the others
 

My Computers

System One System Two

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
Yes, I can do that [I've already considered how best to do it] but the user will have to list the drive letters of all internal fixed disks & partitions so that they can be skipped over.
Once armed with that list, I could readily ensure that all other drive letters are removed before then restoring those generated by the backup script.
- Windows does not list fixed disk & partitions for us unfortunately.
- It will list "removable" disks but it only includes SD cards & USB sticks in that category not external HDDs-SSDs.
- I have been unable to derive any list of fixed disks or any list of external disks.


All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
but the user will have to list the drive letters of all internal fixed disks & partitions so that they can be skipped over.
1. Not sure why. If the restore script derived from the previous installation has those entries should work fine deleting current dosdevices (except os ) then restore from that script.

2. For many people they would only want to escape the os entry when backing up the original dosdevice entries. Then after reinstall delete the new dosdevices ( except os) and restore the rest.

3. Your desire to exclude H and a few others is a bit unusual.

It is more complicated for people who use different osletters for their various installations. Not everybody is addicted to using C as the osletter but that is also unusual. For example an enthusiast could be triple booting. The first os has letter c, the second os has letter d and the third os has letter e. Some enthusiats do that kind of thing.

For the average punter paragraph 2 should do the job.
 
Last edited:

My Computers

System One System Two

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
If the restore script derived from the previous installation has those entries
The user has to list the drive letters of internal fixed disks.
No list of them exists anywhere.

I know which are internal drives and which are not.
- This is the response to fsutil fsinfo drives C:\ D:\ E:\ F:\ K:\ M:\ T:\ V:\
- echo.list vol | DiskPart | find /i "Removable" will correctly identify F:\ & T:\ as removable.
- Nothing will report that K:\ is an external HDD/SSD.
I can write the list in the backup script and can carry it over into the restoration script.
Nobody can do that for me.

Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Why?

I ran your script after commenting out these

dosdev1.jpg
the backup script looks ok

It has included the fixed, removable and usb dosdevice entries as far as I can see.

then to delete current dosdevs after reinstall ( except os ) something like this:

dosdevs2.jpg

this is the output. looks ok.
dosdevs3.jpg
 
Last edited:

My Computers

System One System Two

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
I do not want to alter existing drive letters for fixed internal drives.
If, for example, you had run your amended version on my computer then removing M:\ would cause half an hours remedial work.
It's that need for user intervention that I hoped I'd be able to avoid but cannot.


All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
I had intended to include a self-elevating code block in RestoreAssignedDrives.bat but am having trouble getting it to work
Nice work! This is what I use to self-elevate my batch files:

Batch:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Check to see if this batch file is being run as Administrator. If it is not, then rerun the batch file ::
:: automatically as admin and terminate the intial instance of the batch file.                            ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(Fsutil Dirty Query %SystemDrive%>Nul)||(PowerShell start """%~f0""" -verb RunAs & Exit /B)

::::::::::::::::::::::::::::::::::::::::::::::::
:: End Routine to check if being run as Admin ::
::::::::::::::::::::::::::::::::::::::::::::::::

:: We reach this point once the batch file is run as admin
 

My Computers

System One System Two

  • OS
    Win11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Kamrui Mini PC, Model CK10
    CPU
    Intel i5-12450H
    Memory
    32GB
    Graphics Card(s)
    No GPU - Built-in Intel Graphics
    Sound Card
    Integrated
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 2TB NVMe SSD
    1 x 4TB NVMe SSD
    1 x 4TB 2.5" SSD
    PSU
    120W "Brick"
    Keyboard
    Corsair K70 Mechanical Keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    1Gb Up / 1 Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
  • Operating System
    Win11 Pro 23H2
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkBook 13x Gen 2
    CPU
    Intel i7-1255U
    Memory
    16 GB
    Graphics card(s)
    Intel Iris Xe Graphics
    Sound Card
    Realtek® ALC3306-CG codec
    Monitor(s) Displays
    13.3-inch IPS Display
    Screen Resolution
    WQXGA (2560 x 1600)
    Hard Drives
    2 TB 4 x 4 NVMe SSD
    PSU
    USB-C / Thunderbolt 4 Power / Charging
    Mouse
    Buttonless Glass Precision Touchpad
    Keyboard
    Backlit, spill resistant keyboard
    Internet Speed
    1Gb Up / 1Gb Down
    Browser
    Edge
    Antivirus
    Windows Defender
    Other Info
    WiFi 6e / Bluetooth 5.1 / Facial Recognition / Fingerprint Sensor / ToF (Time of Flight) Human Presence Sensor
Nice work

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
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Even C:\ has been known to vary
Code:
:GetCurrentOsLetter
    set CurrentOsPath=
    set CurrentOSLetter=
    reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v PathName > tmpoutfile.out
    for /F "skip=2 tokens=3" %%i in (tmpoutfile.out) do set CurrentOsPath=%%i
    for /F "delims=: tokens=1" %%i in ("%CurrentOsPath%") do set CurrentOsLetter=%%i

:ProcessEachLine
If "%ThisLine:~0,13%"=="\DosDevices\%CurrentOsLetter%" GoTo :EOF

could include some error checking something like this

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v PathName > tmpoutfile.out
if ERRORLEVEL 1 (
echo Failed to get current OS letter from registry.
goto :wherever
)
 
Last edited:

My Computers

System One System Two

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450

Latest Support Threads

Back
Top Bottom