Skip navigation

JSI Tip 9375. How can I create a Drive letter for a local folder, and have it available to all users?


When you use the subst command to map a drive letter to a local folder, the mapping disappears when you log off.

I have scripted MyDL.bat to map a drive letter to a local folder. The drive letter is immediately available to you, but a restart is required to make it available to all users.

The syntax for using MyDL.bat is:

MyDL Drive: FolderPath

Where Drive: is an unused drive letter, like M:, and FolderPath is the fully qualified path to the local folder. The Volume Label is inherited from the drive of FolderPath and the compression attribute is inherited from the local folder.

NOTE: To delete the drive mapping, use MyDL Drive: DEL

NOTE: MyDL.bat uses REG.EXE built into Windows XP and Windows Server 2003, or REG.EXE from the Windows 2000 Support Tools on the CD-ROM.

NOTE: You must be a local administrator, or have permissions on HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices, to run MyDL.bat.

MyDL.bat contains:

@echo off
setlocal ENABLEDELAYEDEXPANSION
if \{%1\}==\{\} goto err
set DRV=%1
if "%DRV:~1,1%" NEQ ":" goto err
set key="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices"
set FP=%2
if /i "%FP%" EQU "DEL" goto del
if not exist %FP% goto err
set FP=%FP:"=%
set error=N
for /f "Tokens=2" %%a in ('net use^|find ":"') do (
 if /i "%DRV%" EQU "%%a" set error=Y
)
if "%error%" EQU "Y" goto err
for /f "Tokens=1" %%a in ('subst^|find ":\:"') do (
 set wrk=%%a
 if /i "%DRV%" EQU "!wrk:~0,2!" set error=Y
)
if "%error%" EQU "Y" goto err
call :quiet>nul 2>&1
endlocal
goto :EOF
:del
set error=Y
for /f "Tokens=1,2*" %%a in ('reg query %key% /V %DRV%^|FIND /I "REG_SZ"') do (
 set error=N
)
if "%error%" EQU "Y" goto err
call :delq>nul 2>&1
endlocal
goto :EOF
:delq
subst %DRV% /D
REG DELETE %key% /V %DRV% /F
goto :EOF
:quiet
subst %DRV% "%FP%"
reg ADD %key% /V %DRV% /T REG_SZ /F /D "\??\%FP%"
goto :EOF
:err
@echo Syntax: MyDL Drive: folder_path
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish