Creating shortcuts to network locations with authentication on a Windows box

12,869

So what you can do then is run a batch file similar to the one below:

@echo off
net use z: \\server\folder1 /user:jonsmith * /persistent:no
net use y: \\server\folder2 /persistent:no
net use x: \\server2\folder3 /user:jsmith * /persistent:no

This will ask for the password JUST when you first connect to it. Since you can't connect to the same server with multiple usernames, as soon as you authenticate the first time on the server, it will use that username and password for the rest of the connections until you disconnect all the drives or log off

Share:
12,869
Cᴏʀʏ
Author by

Cᴏʀʏ

I work at Corporate Technology Solutions, Inc., a software consulting firm that specializes in custom software development for the financial services industries in the Greater Milwaukee Area in Wisconsin. I earned a Bachelor of Science degree in Software Engineering from Milwaukee School of Engineering. As a consultant and engineer, typical projects for me revolve around full-stack web application development. My strengths include: gathering functional and technical requirements, database design and administration (ssis, sql-server), development (c#, vb.net, aspnet-mvc, sql, javascript, jquery and more), testing, integration, and training. In my spare time I like to read, relax, sample great Wisconsin beer, and of course, contribute to Stack Overflow! Some achievements I'm proud of (Stack Overflow): Usually in the top 1,000 users for all time rank by reputation 38/40 candidate score (if I were to ever run for moderator) c# – gold badge jquery – gold badge javascript – silver badge sql – silver badge sql-server – silver badge I never intend to give bad advice. If you find that any of my answers are counter-productive or just plain wrong, please leave a comment! I'm more than happy to fix or delete answers if they aren't up to snuff.

Updated on September 18, 2022

Comments

  • Cᴏʀʏ
    Cᴏʀʏ over 1 year

    This post is a short novel, so bear with me...

    I'd like to find an effective way to manage a set of shortcuts that point to network locations (e.g. \\server-name\folder) that technically aren't just generic shortcuts (i.e. *.lnk files), which will ask me for credentials if needed. I have come up with a viable solution, but wanted to run my ideas (and "solution") by this community to see if there is a better way.

    So first off, creating a generic shortcut (a *.lnk file) to the network locations works great, and the only reason I'm looking for an alternative is for use with the StandaloneStacks application (which emulates OSX shortcut stacks on Windows). With folder shortcuts, it attempts to drill down the folder structure, when instead I'd like it to simply show me the root folder in Explorer.

    Anyway, some more requirements: I'm not allowed to join the domain. I'm stuck poking around the network by authenticating against each machine as needed. In addition, my network password expires every month so I don't want Windows to permanently remember my credentials or I'll get locked out (3 strikes you're out).

    My first thought was to simply use explorer.exe to launch the network location in an Explorer window, like so:

    explorer.exe /e,/root,"\\server-name\folder"
    

    This works pretty well, but only when I've already been authenticated against the server and Windows is remembering my credentials. If I'm not already authenticated, running that command will take me to my home directory (e.g., C:\Users\Me\).

    I thought about wrapping this with a runas with my network account:

    runas.exe /netonly /user:domain\user "explorer.exe /separate,/e,/root,\\server-name\folder"
    

    Ignoring the fact that I'd have to type my password every single time I wanted to launch a shortcut, this got me closer, except Windows doesn't pass the credentials in the manner I expected; it always shows an authentication failed message ("Unknown user name or bad password"). Due to my rapidly expiring passwords I'd rather not pipe in my password.

    After some more digging I discovered the built-in start command. I can simply put the following in a batch file and it will do what I want:

    start /max "Folder Title" \\server-name\folder
    

    This will launch explorer in a maximized window, take me to the folder, and ask for credentials if it's the first time logging in during my Windows session. The most annoying part is the flashing of the command prompt before it launches the folder. I tried setting the command window to run minimized, but then it also minimizes the prompt for credentials.

    My solution so far is that I have a folder full of little batch files with start commands pointing to all of the locations on the network I frequently visit. I then created shortcuts to these batch files with prettier icons for use with StandaloneStacks.

    So, aside from writing my own little utility to launch shortcuts to network locations, are there any other built-in things in Windows that would work and might be simpler than I what I settled on? I'm using 64-bit Windows 7.

    Other caveats: I jump around from client to client so I can't permanently configure my machine in any way. This rules out creating network locations to the folders I'd like and then creating magic shortcuts to them (using their GUIDs). It also sort of rules out just adding bookmarks in Explorer to these locations (the stacks features is nice, such that I don't have to launch explorer and then pick a shortcut, but that isn't such a bad idea).

    • Canadian Luke
      Canadian Luke over 12 years
      Could you use NET USE?
    • Cᴏʀʏ
      Cᴏʀʏ over 12 years
      @Luke: That might be an option (i.e. mapping drives) if I can prevent it from running on password change days. More than 3 incorrect logins and my account gets locked, and there are definitely more than 3 drives to map. I see you can have it prompt you for a password, but I don't want to type it 10 times. I could probably go with a batch script to collect the password and (re)map all the drives with it...