Jump to content

Recommended Posts

Posted

Hi there,

I'm trying to connect automatically to a network share in a batch file. Til now I used the following method to find the first free drive letter:

for %%a in (l m n o p q r) do (
fsutil fsinfo drivetype %%a:|find "No such Root Directory">nul 2>&1&&call :check %%a:
)
:check
if not defined drvlet set drvlet=%1&goto :eof

But now I want to make it independent from the system language and so I tried something with "net use * \\ server\share", so that the first free drive letter is automatically taken to connect to. Problem is to get the first drive letter into a variable. For now I have the following

For /f "usebackq tokens=2*" %%i IN (`net use * \\server\share`) DO (
echo %%i)

Now I've got the problem to get the drive letter into a variable. So is there any way to use wildcards in an IF statement ( every opinion I found til now, means no ) or how do I get the drive letter in another way into a variable?


Posted

Just found out for myself:

set share=\\server\share

FOR /f "usebackq tokens=2* eol=" %%i IN (`net use * %share% /PERSISTENT:NO`) DO (

SET drvlet=%%i

GOTO endfor

)

:endfor

[\code]

Connects to the "last" free drive letter, means that windows searches for free driveletters backwards and those letters to which a local device was assigned anytime ago, are left out for the first.

Should be system-language independent.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...