Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

windows batch script to map the next available drive letter and store it as a variable

916 views
Skip to first unread message

ksar...@gmail.com

unread,
Feb 4, 2008, 5:35:48 PM2/4/08
to
Here's a batch file you can use to map a server to the next available
drive letter and save that drive letter to a variable.

---------------
@ECHO OFF

rem Map \\server\folder to the next available drive letter and save
the driveletter as DRIVELETTER
FOR /F "tokens=2" %%A IN ('net use * \\server\folder) DO IF NOT %
%A.==command. SET DRIVELETTER=%%A

rem Unmap DRIVELETTER
net use %DRIVELETTER% /del

rem Clear your env variables
set DRIVELETTER=

---------------

For example... if your next available drive letter was Z... ECHO
%DRIVELETTER% would return "Z:"


enjoy~

Ted Davis

unread,
Feb 4, 2008, 8:20:25 PM2/4/08
to
On Mon, 04 Feb 2008 14:35:48 -0800, ksariash wrote:

> Here's a batch file you can use to map a server to the next available
> drive letter and save that drive letter to a variable.
>
>

Since it hardly ever matters whether "next available drive letter" is
counted from the bottom or top of the alphabet, it's simpler to just let
Windows pick the letter:

for /f "tokens=2" %%A in ('net use * \\server\share ^| find "is now
connected"') do set drive_letter=%%A

(All one line - space between "now" and "connected")

--

T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).

Mark Blain

unread,
Feb 5, 2008, 5:42:05 PM2/5/08
to
ksar...@gmail.com wrote in news:8d9ef13d-6298-45ff-970b-b374ecf84874
@j20g2000hsi.googlegroups.com:

In Windows 2000 or higher, PUSHD and POPD are another way to map a server
share temporarily to a drive letter.
http://support.microsoft.com/kb/317379

0 new messages