The net use command in Windows allows you to manage your remote connections, letting you easily map drive letters to network resources and making sure that you’re always connected to the right network and domain. You can also use it to pass user credentials, letting you log into remote computers without entering your password over and over again. Let’s take a look at how this works.
Create a batch file
The net use command is a great way to connect to network resources, but it can be a pain if you have to enter your credentials every time. If you’re tired of typing in your username and password, there’s a way to pass your credentials along with the net use command. Here’s how Include the following text at the top of your batch file:
Add commands to store and retrieve data
To store data, you need to use the set command. This command will take two arguments: the name of the variable and the value you want to store. For example, to store the username example_user in a variable called USERNAME, you would use this command The net use command is used to map network resources. In order for it to work, you must provide credentials that allow access to these resources. The following text will show how we can do this by using the stored credentials from our previous example with an argument on the net use command line -u USERNAME –p PASSWORD. We could also just specify USERNAME PASSWORD as the second argument if we wanted to use those same credentials again.
The first parameter specifies which account should be mapped and the second parameter specifies what password should be used when connecting.
Store username and password in the registry
Storing your username and password in the registry can be a convenient way to manage your net use credentials. To do this, you’ll first need to open the Registry Editor by clicking Start and then typing regedit into the search bar. Once the Registry Editor is open, navigate to HKEY_CURRENT_USER\Software\Microsoft\Command Processor. In the right pane, create a new String Value and name it AutoRun. Double-click on the new value and enter the following command: net use * /user
Retrieve username and password from the registry
When you use the net use command, you need to specify a username and password. The problem is that this can be a pain to type in every time. So, instead, you can store your credentials in the Windows Registry and then just reference them when you need them.
Here’s how to Open up the Registry Editor by typing regedit into the search bar. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon. Find Username and change its value to whatever you want it to be called. Do the same for Password, but leave Value Data blank (password will show up as *****). Save changes.
Save all of your work on any open files before continuing! If you close something out of laziness or accident, don’t worry: all of your changes are safely saved within the registry file itself, so they’ll come back once you restart your computer or log out and back in again.
Use net use to gain access (Connect To)
The net use command is a handy way to connect to resources on your network, but did you know that you can also use it to pass user credentials? This can be useful when you need to connect to a resource that is not in your current domain.
To use the net use command, open a command prompt and type:
net use * \\server\share
where the server is the name of the remote server and share is the name of the shared folder you want to access.
If you don’t specify a username or password, you will be prompted for one.