If you need to determine the 'server name' and 'share name' of a drive letter that was mapped with the net use command,
you can call drivemap <DriveLetter> in your batch file. Drivemap.bat returns the
server component of the mapped drive in the server environment variable and returns the share name in the the
share environment variable. If the drive is not mapped, or you do not provide a valid drive parameter, both
environment variables are set to None. Drivemap.bat contains:
@echo off setlocal set server=None set share=None if \{%1\}If your CMD parser is pipe ( | ) challenged, you can use the following script:\{\} goto end REM Clean up drive letter parameter set dl=%1 set dl=%dl::=% set dl=%dl:"=% set dl=%dl:\=% set dl=%dl%: if not exist %dl%\*.* goto end for /f "Skip=1 Tokens=3* Delims=\ " %%i in ('net use %dl%^|findstr "Remote name"') do set server=%%i&set share=%%j :end endlocal&set server=%server%&set share=%share%
@echo off setlocal set server=None set share=None if \{%1\}\{\} goto fin REM Clean up drive letter parameter set dl=%1 set dl=%dl::=% set dl=%dl:"=% set dl=%dl:\=% set dl=%dl%: if not exist %dl%\*.* goto fin for /f "Skip=1 Tokens=1-3* Delims=\ " %%i in ('net use %dl%') do call :parse %%i %%j %%k "%%l" :fin endlocal&set server=%server%&set share=%share% goto end :parse if not "%1"=="Remote" goto end set server=%3 set share=%4 set share=%share:"=% :end
0 comments
Hide comments