February 2, 200620 yr I'm trying to figure out how to get the next available drive letter.I know that if I use the command:net use * \\computername\sharename *it will map to the next available drive letter. In this case, Y:\. How do know that if I'm trying to automate a batch script though?Any help is greatly appreciated. Edited February 2, 200620 yr by Sonic
February 2, 200620 yr what are you trying to do? why not set the drive letter instaed of letting it choose one itself?
February 2, 200620 yr Author I'm trying to set up a script for others to use to install programs. I'm not fully aware of all that happens in this IT Department just yet since I've only been working here for a month.There may be reserved drive letters or random changes that I have no control over nor know about in the future. I'm only going to be around for 3 more months so I wanted to make something that is somewhat universal.The name of the computer isn't going to change after I leave. In my VMware tests, scripts seem a little more responsive if you use a constant drive letter as opposed to the network path.
February 2, 200620 yr Using a drive letter vs. UNC shouldn't be any faster or slower. If you want something that is going to be universal and doesn't interfere with other already mapped network shares then just stick with the UNC.If you stick with mapping the drive you should add /PERSISTENT:NO to the NET USE command so the drive doesn't automatically remap the next time they logon.
February 2, 200620 yr You can probably setup an IF STATE check in your batch script so it looks for drive letters that have already been taken, and then takes the one thats not...I'm not very good with writing batch files though ^_^
February 2, 200620 yr speaking from experience here, it is a lot better to ensure that all users have the same drive letter for the same sharesthat way when somebody rings up and says "i cant see f: drive!" or "i havent got access to XYZ in z: drive) you will be able to fix the problem much quickerjust my 2 cents
February 3, 200620 yr I'm running this in a batch to connect the share to the last free drive letter and write it to %drvlet%FOR /f "usebackq tokens=2* eol=" %%i IN (`net use * \\server\share /PERSISTENT:NO`) DO ( SET drvlet=%%i GOTO endfor ) :endfor
February 7, 200620 yr Author Using a drive letter vs. UNC shouldn't be any faster or slower. If you want something that is going to be universal and doesn't interfere with other already mapped network shares then just stick with the UNC.Sorry, when I said more responsive, I meant actually working. XCOPY tends to die on me when I try to copy all relative files (i.e. ".\*.*") from an Everyone Full Control network share. When I say die, I mean that nothing is copied. It keeps saying "0 file(s) copied".speaking from experience here, it is a lot better to ensure that all users have the same drive letter for the same sharesthat way when somebody rings up and says "i cant see f: drive!" or "i havent got access to XYZ in z: drive) you will be able to fix the problem much quickerI think that I got into a bit of this above. I don't have a full listing for everyone's possibly network drives upon logon. As a result, I'm just trying to do this so that anyone can use it.I'm running this in a batch to connect the share to the last free drive letter and write it to %drvlet%FOR /f "usebackq tokens=2* eol=" %%i IN (`net use * \\server\share /PERSISTENT:NO`) DO ( SET drvlet=%%i GOTO endfor ) :endforThis looks like it's exactly what I need. I'm not too familiar with the FOR loop command nor conditionals in DOS. What exactly is the exit condition in this code?I know what it does since you typed that up in response to what I'm asking for. But can you or somebody else just explain it a little more?
February 7, 200620 yr Hi Asin,here a little explanation to the for loop ( i hope it is not to confusing ):The command "net use * \\server\share /PERSISTENT:NO" connects the share to last free drive letterThe for loop would process every line of the output of the command, if there wouldn't be the goto :endfor But because of the goto :endfor, only the first line, which already contains the drive letter is processed.The usebackq options just changes the use of ' and ". The tokens=2* says that the second word is written to the variable %%i, the * within says, that the rest is written to variable %%j.I hope this makes the batch a little more clear, I you've got any questions left, don't be shy to ask again
Create an account or sign in to comment