Automatic Drive Mapping
In one of the comments on Providing User Feedback In AutoIt, Jim is wondering how you can map drives:
I was wondering though, can autoit make an executable that would setup a permanent drive map. Instead of a non-technical user mapping a drive, the executable file would setup a predefined mapped drive. That would be cool..
Thanks
Jim
Well, Jim, there are several different ways that you can map drives but two of the easiest are using a batch file or through AutoIt. Now I know that you can’t make a batch file into an executable but I thought that I would show you how todo this anyway.
Our Example
For this post, I want to use an example to help clarify these concepts. For our example, we would like to map drive letter T: to network share \\server\share.
Batch File
To map a drive in a batch file, simply use the net use command. So, for our example, we would use:
net use T: \\server\share
If you want the drive mapping to return each time you reboot, add the /persistent:yes option:
net use T: \\server\share /persistent:yes
AutoIt
In AutoIt, you use the DriveMapAdd command. Our example would look like this:
DriveMapAdd("T:","\\server\share")
To allow it to survive a reboot, add one more option:
DriveMapAdd("T:","\\server\share",8)
That’s all there is to it. You can then compile this into an executable and away you go!
Hope that answers your question, Jim
If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?
8 Responses to “Automatic Drive Mapping”
-
D Steele Says:
March 18th, 2007 at 12:34 pmCan’t convert a batch file to an executable? Try searching Google on ‘batch file to executable’.
In particular, I found this link on Lifehacker - apparently Windows itself comes with this ability. It looks pretty interesting, although I haven’t tried it myself:
http://renegadetech.blogspot.com/2006/07/how-to-convert-bat-file-or-vbs-file.html
-
Tim Fehlman Says:
March 18th, 2007 at 12:48 pmGood catch, D. Steele. I wrote that and then realized that I was wrong but I was caught up in a different part of the post. By time I finished the post I forgot about it.
I am actually writing a post about how to do this in AutoIt that I will be posting later this week.
Tim
-
Soren Says:
March 19th, 2007 at 5:22 amY’know - I think this “use AutoIt for everything you possibly can tendency” is getting too much. It’s practical and can be used for many things, but this is the worst, and most ridiculous example I’ve seen so far.
Why on Earth would you want to compile a script into an exe file to map your drives? - it’s stupid!
You already HAVE the function to do it, built into Windows - it’s there, it works and it’s in cleartext and can be easily changed.
By using AutoIt to compile an exe to do it instead, is basically just swapping an easy, standardized and well documented way of doing it, with another (and not as well documented) language and is ONLY a way of making EVERYTHING harder than it should be.
If Jim was only /wondering/ how to do it - then ‘OK’ - it’s always nice to learn some new functions, but if he actually /wants/ to use it, then he’s clearly not too bright.
Sorry.
-
Tim Fehlman Says:
March 19th, 2007 at 6:49 amSoren,
One important foundation of DCoT is options. As I pointed out, yes, you can map a drive with the built in net use command. But, what if you are writing an AutoIt script? It is nice to know that you can perform this action without having to pass the responsibility on to a third party.As for using AutoIt for everything, well, AutoIt is my tool of choice. This is what I do most of my development in because it is a way for me to make quick apps that are easy to create. I am not a developer. I am an IT guy so I don’t have the need for many of the higher end tools. AutoIt is a great addition to my toolset.
Also, judging from your comment, you may have missed my 14 Windows Command Line Tricks post. And you are probably not going to like today’s post either.
One last thing, I would like to encourage you to keep an open mind about things. Once you decide that an idea is wrong or stupid, you have closed your mind to and possibility and potential that idea may have which reduces yourself as a person. Just because you can’t think of a reason why someone may want to map a drive in an AutoIt script does not mean that it is a stupid idea. It may just mean that you have not had enough experience to know why you would want to do this.
And in my opinion, the “not too bright” thing is berating someone for wanting to expand their knowledge and understanding and then rebuking the person who is willing to help. Remember, it is always easier to tear down than it is to build up.
Tim
-
Greg Groth Says:
March 19th, 2007 at 10:44 amFYI don’t map a drive to the next possible drive letter on your machine. Windows likes to assign this letter to USB drives and it acts screwy if you use it for mapping.
-
Soren Says:
March 20th, 2007 at 5:53 amTim,
I agree with you - if you prefer to use a specific utility, then it’s nice to know what you can do with it, and how.I also don’t have a problem with AutoIt. To be quite honest I’ve made utilities a few times, in both Pascal and Delphi, with the intent to run them in a network from the logonscript, so it’s a bit doublestandard’ish to say that I wouldn’t using something compiled there - although they /have/ been a little more advanced than a “net use” command.
I’m an IT guy too, and a programmer, and I regularly use homemade programs to make my job easier, so I don’t see a problem at all in automating things and making your life easier using AutoIt.
The thing was just…if the idea was to use AutoIt /just/ for attaching network drives, then I still feel it’s a waste of time.
- if attaching network drives is just a part of something bigger, then it sounds like a much better idea.
I /did/ read the “14 Windows Command Line Tricks” post. I liked it…personally I didn’t learn much, but it WAS a good post (I’ve been an IT guy for a long time).
As for the “not too bright” comment - just ignore it - I’m chronically grumpy…that’s just the way I am. *sigh*
Since we’re talking command line tricks …a small contribution;
Having been an IT guy for a long time, I do feel very much at home in a DOS window and I’ve never really gotten the idea behind the way files are sorted when you do a DIR.So nowadays, whenever I setup a Windows computer, I add “dircmd=/o:gn” to the enviroment variables (or the “set dircmd=/o:gn” command to the autoexec back in the Win3/9x days). Your filelistings will now be sorted alphabetically with the folders at the top of the listing.
You can find this in lots of places, but would one be searching for it if they didn’t know of the possibility? - probably not, but since many people coming here are reading your site for all the helpful ideas they can get here, perhaps this’ll be useful to someone.
…that is, the few people left in the world that uses a DOS prompt.
Keep up the good work,
/S -
Tim Fehlman Says:
March 20th, 2007 at 8:31 amSoren,
I can appreciate where you are coming from. I have also been in the industry for several years and I look at how some of the “new generation” do things and I think to myself, “Are you nuts?”And that is actually one of the big motivators behind Daily Cup of Tech. I think there is a lot of “lost art” to computing that some of us “old guys” can bring back and I would like to give people the opportunity to present that here.
For example, your environment variable tip is excellent! I use one very similar myself and I was going to make this a post entry but I will probably now use your comment as the catalyst. But, as you said, most people aren’t even aware that this is possible.
As for being grumpy, I don’t think you can truly call yourself an IT guy if you aren’t ticked off at the world at least every once in a while. You should hear some of the stupid things I’ve said in the past! (Once told my boss that he was to stupid to have authority over me and that he should be thanking me daily for the opportunity to work with me. I lasted about another week before they game me a very nice severance package and provided me with an opportunity to find financial success elsewhere!) IN the end, no biggie!
Thanks for replying to my comments and allowing us to have a civil dialog about this. This is how I like to see differences of opinion settled on DCoT. I think that you have a lot to offer the IT community in general and DCoT specifically and I’m glad you are a regular reader and contributor.
Long live the DOS prompt!
Tim
-
Clayton Says:
October 24th, 2007 at 8:30 pmI’m new to AutoIT, and really like the look of the program. While I do have quite the technical background, I’m not technically an IT Guy. Instead I train technical support agents and customer service agents in a call center environment. We do have 1 IT guy on location, but to support 300 machines. The network setup isn’t quite the best, and I know some of this could be automated, but have a question about this particular script.
Each user has an individual share on a network drive, and the login of the user is actually the directory of their share. so, the resource looks like this ‘\\server\folder\username\’.
Is there a way to pull the login either based on user input or automatically from the windows xp machine they are logged into and running the script on?

