Doc Symbiosis Posted September 14, 2005 Posted September 14, 2005 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:):checkif not defined drvlet set drvlet=%1&goto :eofBut 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 followingFor /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?
Doc Symbiosis Posted September 15, 2005 Author Posted September 15, 2005 Just found out for myself:set share=\\server\shareFOR /f "usebackq tokens=2* eol=" %%i IN (`net use * %share% /PERSISTENT:NO`) DO (SET drvlet=%%iGOTO 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.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now