Asin Posted February 2, 2006 Posted February 2, 2006 (edited) 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, 2006 by Sonic
bledd Posted February 2, 2006 Posted February 2, 2006 what are you trying to do? why not set the drive letter instaed of letting it choose one itself?
Asin Posted February 2, 2006 Author Posted February 2, 2006 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.
nmX.Memnoch Posted February 2, 2006 Posted February 2, 2006 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.
EchoNoise Posted February 2, 2006 Posted February 2, 2006 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 ^_^
eyeball Posted February 2, 2006 Posted February 2, 2006 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
Doc Symbiosis Posted February 3, 2006 Posted February 3, 2006 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
Asin Posted February 7, 2006 Author Posted February 7, 2006 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?
Doc Symbiosis Posted February 7, 2006 Posted February 7, 2006 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
robotnik Posted September 18, 2008 Posted September 18, 2008 Thanks Doc! That's exactly what I needed and it works great too!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now