On Fri, 04 Sep 2020 21:37:04 GMT, MajorLanGod wrote:
> I reserved a drive letter for each specific USB drive.
Thank you for your purposefully helpful advice, where I'm well aware
that I'm asking for a solution to a problem that can have many solutions,
but where any one good solution is useful for everyone to benefit from.
The option to force the drive letter is certainly one option I've considered.
o How to Assign a Persistent Drive Letter to a USB Drive in Windows
<
https://www.howtogeek.com/96298/assign-a-static-drive-letter-to-a-usb-drive-in-windows-7/>
But I'm seeking something more flexibly elegant, in that it should
ascertain the drive letter on its own, in order to edit files on
that drive letter.
Note that my sole purpose is to maintain a system log by typing:
Win+R > syslog
Where the AppPaths key in the registry must edit that file:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\syslog.exe
DEFAULT == (anything that edits the syslog file on an external USB drive)
The syslog file is stored on an external USB drive (for safety).
Where the trick is figuring out the path to that syslog file.
And where, for each PC, that syslog file will be unique.
But the same USB flash drive will be used for all PCs.
> Windows also allows one to Name each drive, and I assume there is a way
> to examine that name without too much trouble.
Thanks for your purposefully helpful advice.
There are a bunch of approaches, each with its own pros and cons.
I'm slowly working through them as we speak.
For example, the Windows "vol" command tells us the volume name
if we know the drive letter.
C:\> vol X:
Volume in drive X is FOOBAR
Volume Serial Number is 2521-FEB4
On the other hand, if you know the volume, you can find the drive:
@echo off
:: Given the volume name, it reports the drive letter
setlocal
set vName=%1
if [%1]==[] set /p vName=Enter volume to search for:
set n=0
set ltrs=ABCDEFGHIJKLMNOPQRSTUVWXYZ
:Loop
call set ltr=%%ltrs:~%n%,1%%
set /a n +=1
vol %ltr%: 2>nul|find /i " %vname%">nul||if %n% lss 26 goto :loop
if %n% equ 26 (set "ltr="
echo No matching volume label found.
) else (echo Volume %1 is drive %ltr%:)
endlocal & set ltr=%ltr%
pause
Without knowing either, this will show all the removable USB drives:
@Echo off
setlocal enabledelayedexpansion
Set "USB="
REM get removable loaded drives:
for /f "tokens=1-5" %%a in (
'wmic logicaldisk list brief'
) do if %%b Equ 2 if %%d gtr 0 Set USB=!USB! %%a
Echo:Usb removable drives:%USB%
EndLocal&Set USB=%USB:~1%&Goto :Eof
Without knowing either, this outputs the last removable drive:
@echo off
::
https://stackoverflow.com/questions/19103950/running-batch-file-from-usb-drive-when-drive-letter-changes
:: Drivetypes
:: 0=Unknown
:: 1=No Root Directory
:: 2=Removable(USB,Firewire)
:: 3=Local Disk (Internal Hard Drive)
:: 4=Network Drive(\\Server\share\)
:: 5=Compact Disk (CD DVD)
:: 6=Ram Disk
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=2"
get name /format:value') do set driveletter= %%d
echo %driveletter%
pause
However, given the point is to easily edit a system log file on an external
USB drive, I may make use of the fact that unique file and folder names
will exist on that external USB drive.
For example, this script looks promising given the USB stick has a unique
folder and file that I'm attempting to edit (even as the USB drive letter
won't be unique as it can change each time it's inserted into the PC):
@echo Find a drive that has a root folder titled "software".
::
https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-identify-drive-letters
@for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do @if exist %%a:\software\ set SW_DRIVE=%%a
@echo The "software" root folder is on drive: %SW_DRIVE%
:: @dir %SW_DRIVE%:\software /w
@vim %SW_DRIVE%:\software\machine1\syslog.txt
--
Note that my sole purpose is to maintain a system log by typing:
Win+R > syslog
Where the AppPaths key in the registry should edit that file:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\syslog.exe
DEFAULT == (anything that edits the syslog file on an external USB drive)
The syslog file is stored on an external USB drive (for safety).
Where the trick is figuring out the path to that syslog file.
And where, for each PC, that syslog file will be unique.
But the same USB flash drive will be used for all PCs.