How to connect to network drives from the command line using the network (2023)

One of the most ubiquitous commands in an experienced Windows administrator's arsenal is probably Windows.Internetdomain🇧🇷 This command has many functions. Read this article to learn more about him.net use.

No reader? Check out this related tutorial video!

Don't you see the video? Make sure your ad blocker is disabled.

onet useThe command is an older but fully functional command for creating, deleting, and managing Windows SMB connections and mapped drives.

let's divenet useand describes what it is capable of and how to use it in this tutorial.

Index

requirements

To follow the examples in this tutorial, make sure you have at least the following:

  • A Windows client computer (any version will work) in an Active Directory domain. This tutorial uses Windows 10.

onet useThe command works in non-domain environments. Otherwise, you must always pass a username and password to authenticate the remote file share.

  • A user account with read access to the file share and NTFS read permissions for the folder the share points to

Begin withnetwork usage

onet useThe command allows you to work with files on network file shares. This is done with various parameters and switches as shown below.

How to connect to network drives from the command line using the network (1)

onet useThe command can display device connections, create new connections, and delete them. In this tutorial, you'll learn about each parameter and see what use case each parameter is for.

You will see a lot of the content therenet useyou refer to the endpoints you work with as "connections" instead of "entities". This command can connect to printers and other devices, but for this tutorial we will focus on remote file sharing.

(Video) How to Map Network Drive using Command Line

Create remote connections

Creating new connections is one of the most common reasons to use it.net useDomain. This command allows you to connect to remote file shares to copy files, delete files, etc. as if the folder you are connecting to is local.

To create a new remote file sharing connection, you have two optionsnet use🇧🇷 You can create what Microsoft calls a "no device" connection, which is simply a file sharing connection with no drive letter or drive assigned.

Map network drives with credentials

Mapping network drives is one of the most common uses ofnet useDomain. This command allows you to map a network drive from the command line as usualvia file explorer.

Assuming you are on a Windows 10 PC in a domain environment with a Windows server hosting a file share:

1. Open a command prompt or PowerShell console as an administrator.

Related:How to run PowerShell as administrator

2. Let's map the drive letterF:For himDEVSRVShare server filesSwiss francs🇧🇷 To do this, specify the drive letter to map the network drive, followed by theruta UNCfrom the remote file share.

uso neto f: \\DEVSRV\c$

You can use any letter to map the network drive if it is not already in use.

If the shared file contains spaces, always enclose them in quotes, e.g.\\DEVSRV\"My File Share".

How to connect to network drives from the command line using the network (2)

3. Run nownet usethere are no parameters to confirm that Windows correctly mapped the drive.

How to connect to network drives from the command line using the network (3)

4. Open File Explorer and you will also notice a new network location.

(Video) Mapping of Network Drives in Windows Clients via Command Prompt

How to connect to network drives from the command line using the network (4)

If you don't care which device (drive letter) you want to map the drive to, you can also use an asterisk (*) for the drive letter. This will tell Windows to look for the next available drive letter.

How to connect to network drives from the command line using the network (5)

Map network drives with alternate credentials

If you performed the previous demo and mapped a network drive, you have authenticated as a logged in user. But what if you need to authenticate to the remote file share using alternate credentials?

Mapping an authenticated network drive as a non-logged in user account is almost the same as with a logged in account. The only difference is that a few more parameters are used.

To map a network drive with alternate credentials, open a command prompt or a PowerShell console as an administrator.

pick upnet useDeployment:

  • The drive letter to map
  • The UNC path of the file share
  • The username for authentication (/Ella)
  • the password

In the following example, Windows maps drive F: to the \\DEVSRV\c$ file share by authenticating astest_userAccount inDomaindomain with passwordpassword here.

net use f: \\DEVSRV\c$ /u:domain\\test_user contraseñaaqui

Specify a local user account on the remote computer, for example by removing the domain from the username parameter/u:user_test.

use the/saved-Parameter to save the credentials so that you are not prompted for the password later.

Create "no device" connections (no drive letter)

You may need to use a remote file share, but you don't want to assign a drive letter to it. In this case, simply delete the drive letter.

Let's create a file sharing connection without a drive letter, called a "no device" connection. Assuming you are on a Windows 10 PC in a domain environment with a Windows server hosting a file share:

1. Open a command prompt or PowerShell console as an administrator.

(Video) Windows: Mount and unmount network drives on the command line

Related:How to run PowerShell as administrator

2. Create the "no device" connection by specifying theruta UNCFor the remote file, provide a username and password for authentication and press Enter.

net use \DEVSRV\c$ /u:domain\test_user passwordhere

If both the client computer and the remote Windows server are in an Active Directory domain, and you are logged on to the client computer with a domain user account, this is typically not helpful.net usein this situation. Now you can access these features without any additional steps. But if you need to authenticate with an alternate user account, this is useful.

The connection is established, but if you look in the file explorer, you don't see a connection. This connection is "no device".

How to connect to network drives from the command line using the network (6)

3. Now confirm that the connection has been established by runningnet useno parameters. You can see below that Windows knows there is a connection.

How to connect to network drives from the command line using the network (7)

At this point, you can browse and work with the file share as if it were local, using the alternate user account credentials.

How to connect to network drives from the command line using the network (8)

lasting connections

When you make new connections, Windows can keep those connections after a reboot or without calling persistence. EITHERnet useThe command has a parameter called/strong headedwhich defines whether or not a connection persists after a reboot.

To ensure that the connection is maintained, add the/strong headedParameters for each attempt to establish a new connection, such as:

net use \\DEVSRV\c$ /persistent: ja

Mapped drives are not persistent by default.

(Video) Map Drives using Windows Batch File

Windows remembers the persistence settings of the last connection created. if you define/strong headedtowardssimulatorFor one connection, all subsequent connections are persistent unless you explicitly set it to be./strong headedtowardsno🇧🇷 To ensure that all connections remain in the current session, use net/persistent use: and.

Advanced connection parameters

Most of the time, you only need the parameters discussed above to establish a connection. However, there may be times when you need to perform some advanced connection tasks.

Drive mapping writable (forced drive access)

Added in Windows 10 Build 1809, you can use/write-Parameter to map a drive that bypasses all operating system caches and forces I/O through the disk.

increased security

onet useThe command also has two advanced parameters that increase security;/reguireintegritymi/Need privacythrough a resource calledUNC Protected Access🇧🇷 This feature "flags" the information on these shares to inform Multiple UNC Providers (MUPs) and UNC Providers of additional security requirements

Use of/requires integrityThe parameter provides additional integrity checks to block tampering attacks.

o/Need privacyparameter commandsnet useUse encryption to prevent third parties from seeing sensitive information in file share communications.

Delete network connections

Eventually, when you have connections configured and need to remove them, the/ClearThe parameter is your friend. To remove a non-persistent connection, enter the/Clearand the UNC path to the network share as shown below.

net use /delete \\devsrv\c$
How to connect to network drives from the command line using the network (9)

To remove a mapped drive, specify the drive letter and the mapped drive

net use f: \\devsrv\c$ /delete

conclusion

You should now have a good idea of ​​what you can do with it.net useDomain. This old but useful command is still used today and can still help you map network drives in Windows.

how will you usenet use?

Videos

1. How to map and share network drives with Command Line
(Miss Robot)
2. List mapped network drives from the command line to text file (3 Solutions!!)
(Roel Van de Paar)
3. How to Map Network Drive from Command Prompt
(EME Technologies)
4. Network Troubleshooting using PING, TRACERT, IPCONFIG, NSLOOKUP COMMANDS
(sakitech)
5. Mapping network drives from PowerShell
(David Dalton)
6. How To Map a Network Drive using CLI
(learnITstuff)
Top Articles
Latest Posts
Article information

Author: Dan Stracke

Last Updated: 02/17/2023

Views: 6013

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.