Recently I’ve been accessing a lot of network resources from Windows. This is pretty easy in principle, but can become complicated when there are various credentials available, and each set of credentials provides a different level of access.
For example, a single share may have two different levels of access based on two unique usernames and their corresponding passwords. The first provides read only access, the second provides full write access. There may be times that it’s desirable to be connected read only and other cases where you require full write access.
That’s where the ‘net use’ command comes in. You can learn more about net use here. In this article I cover these cases.
- Connect to a network resource (authentication)
- Disconnect from a network resource. This is generally in order to reconnect with different credentials.
Connect to a network resource
This is really pretty easy to do. You begin by opening up the windows command line. Lately I like to use Console2 more than the built in command line. If you wanted to connect to the network share “\\myhost\myresource” and the domain, username and password were respectively “mydomain”, “myuser” and “mypass” the command you would type in is:
net use \\myhost\myresource mypass /USER:mydomain\myuser
It’s also possible to leave out the password in the above example and you will be prompted as follows:
The password is invalid for \\myhost\myresource. Enter the password for 'mydomain\myuser' to connect to 'myhost':
That way you don’t inadvertently cache the password in the history of your console window (although this is more short lived than in Linux since it clears each time the window is closed).
It is also possible to leave out the domain and provide just a username if a domain isn’t used for authentication on your network.
Disconnect from a network resource
Disconnecting wasn’t obvious at first, but it’s really quite easy. Simply use the “/d” option to delete the cached credentials for the specified resource.
net use \\myhost\myresource /d /yes
What’s surprising is that Windows only has a command line interface to accommodate these details 🙂