|
Answer» In one of my scripts there is a command to map a network drive to the next available drive letter. I'd like to create a shortcut to this drive mapping on my desktop. To do this I thought about setting the drive mapping equal to a variable that I COULD then POP into a VBScript that creates the shortcut.
This Code: [Select]net use | find "<part of unc path>" allows me to identify what drive letter was assigned to the mapping and after that I think I need to use a for loop to set the variable equal to the output of the net use command but I'm wondering if there is a better way to do it?
Thanks
MJ
This will map a temporary letter and let you execute batch commands - if you have permissions to access the share.
Code: [Select]pushd "\\server\share" dir pause popdThanks foxidrive, I use pushd/popd in most of my scripts so I can run them from the NAS . We can even use it for this example - how would you create a shortcut on the desktop to the drive mapping created by pushd?
Thanks,
MJI'm not sure what your task is. If you have permissions to access the share then create a shortcut to this batch file, it will tell you the drive letter and pause. When you hit a key it will disconnect the drive letter.
Code: [Select]@echo off pushd "\\server\share" set "drive=%cd:~0,2%" echo "%drive%" pause popd Thanks again foxidrive. I think I can use what you gave me.
I'll explain a little about my script. I keep a shortcut to it on every server I maintain. When I log onto the server I run the script and it configures a number of things for me so I can get around on the server, get out to the Internet, etc. RATHER than add the dozens of little utilities that I use to a menu in the script I map a drive to the folder where all the utilities are stored.
I don't always need utilities here so it's a bother to have the drive mapped then automatically opened. I don't like clicking Start > Computer >
Instead I want the script to create the drive mapping (like I already do) and a shortcut to the drive on the desktop (quicker access ) Because the path that is mapped uses the next available drive letter I need logic that can identify the drive mapping and create a shortcut to it on my desktop. So I wrote it here.
I CHOSE to use Net Use in the script because I had already used pushd.
I think that explains it all.
Thanks,
MJ
Is drive Z: always free on your servers?
You can specify the drive letter in net use and you can check if the drive letter exists before hand.Not always. There are several clients we setup specific drive mappings for so I will need to use the next available drive letter to be sure. Yes, do that.
Code: [Select]@echo off for %%a in (z y x w v u t s r Q p o n m l k j i h g f e d c) do if not exist %%a:\ do set drv=%%a: net use %drv% etc
|