NET USE

Map a drive letter to a shared printer or file share (Drive Map).

Syntax
      NET USE [devicename | *] [\\computername\sharename[\volume] [password | *]]
         [/USER:[domainname\]username]
         [/USER:[dotted domain name\]username]
         [/USER:username[@dotted domain name]]
            [/SMARTCARD] [/SAVECRED] [[/DELETE] | [/PERSISTENT:{YES | NO}]]

      Map to the current user's home directory as specified in the users Active Directory record:
      NET USE {devicename | *} [password | *] /HOME

      Set defaults:
      NET USE [/PERSISTENT:{YES | NO}]

Key
   Devicename   A local drive letter or printer device e.g. S: Z: LPT2:
                Specifying an asterisk (*), will use the next available drive letter.

   Sharename    A printer or file share on the network (UNC path).

   /USER        A different user name with which to authenticate the connection.
                Default=current user.

   DomainName   A different domain to connect to for authentication.
                If you omit DomainName, NET USE will use the current logged on domain.

   /SAVECRED    Store the provided credentials for reuse.

   /SMARTCARD   Use the credentials on a smart card for the network connection.
                If multiple smart cards are available, you will be prompted for a credential.

   /PERSISTENT  Controls the use of persistent network connections.
                The default is the setting used last. Deviceless connections are not persistent.
                Yes saves all connections as they are made, and restores them at next logon.
                No  does not save the connection being made or subsequent connections.
                Use /delete to remove a persistent connection.

   /HOME        Connect a user to their home directory.

   /DELETE      Disconnect the specified network connection.
                Specifying an asterisk (*), will remove and disconnnect all network mappings.

To map a drive to a network resource, File and Printer sharing must be enabled on the remote (server) computer.

NET USE command can map a network printer to an LPT port (for DOS type applications that print to a port.) but this does not add the printer to the Control Panel.

By default all mapped drives have a 15 minute idle session timeout, you can modify this with the NET CONFIG command. This behaviour is designed to improve overall performance.

Drive Descriptions

Windows explorer displays a drive description for each share, while this can be edited in the Explorer GUI. The text is stored in the registry.

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##ComputerName#ShareName
_LabelFromReg=<description of drive mapping>
   (string REG_SZ)

Examples

Join a file share (Drive MAP):

NET USE [driveletter:] \\ComputerName\ShareName /PERSISTENT:YES

NET USE [driveletter:] \\ComputerName\ShareName\folder1\folder2 /PERSISTENT:No

NET USE H: /Home
NET USE J: \\MainServer\Users\%Username%
NET USE W: \\MainServer\GroupShare /Persistent:No
NET USE \\MainServer\SharedPrinter

MAP to a OneDrive Personal with a cid of 646464 (https://onedrive.live.com/?cid=646464). For OneDrive for Business use SUBST instead.

NET USE O: https://d.docs.live.net/646464 /Persistent:Yes

Make all future connections persistent (auto-reconnect at login):

NET USE /Persistent:Yes
or
NET USE /P:Yes

Make all future connections non-persistent (reconnect with login script):

NET USE /Persistent:No
or
NET USE /P:No

Join a file share (Drive MAP) - with a long share name:

NET USE [driveletter:] "\\ComputerName\ShareName"

Connect a user to their HOME directory:

NET USE [devicename | *] [password | *]] [/HOME]
This requires the users Home server/folder to be defined in AD

In a script, to map a drive and wait until the mapping has completed before continuing:

START /wait NET USE [driveletter:] \\ComputerName\ShareName
This will be a little slower, but ensures that files can be read from the mapped drive.

Join a Printer Share:

NET USE [LPTx:] \\ComputerName\printer_share /PERSISTENT:YES

Join a Printer Share - with a "long" share name:

NET USE [LPTx:] "\\ComputerName\printer_share"

Disconnect from a share:

NET USE [driveletter:] /DELETE

Disconnect from a share and close all resources (undocumented):

NET USE [driveletter:] /DELETE /Y

Map a drive using alternate credentials - this will prompt for a password:

NET USE G: \\Server64\Share1 /USER:SS64dom\user64

Map a drive using alternate credentials, passing a password credential (this must be run from PowerShell):

PS C:\> "s5QxXkwnOxt3MuNlgY6E" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File C:\temp\credential.txt
PS C:\> $SecString = get-content C:\temp\credential.txt | ConvertTo-SecureString
PS C:\> $cred = New-Object System.Management.Automation.PsCredential('SS64dom\user64',$SecString)
PS C:\> New-PSDrive -name G -Root \\Server64\Share1 -Credential $cred -PSProvider filesystem -Persist

The password can be decrypted only by the user who encrypted it, on the same machine.

“Two roads diverged in a wood, and I-I took the one less traveled by, And that has made all the difference” ~ Robert Frost

Related commands

VB Script: MapDrive [ example ]
VB Script: Add Printer Connection [Examples]
NET.exe - Manage network resources.
NET SESSION - List or disconnect open files.
NET SHARE - Create file share.
OPENFILES - List or disconnect open files, local or remote.
PRNMNGR - Add, delete, list printers and printer connections.
PUSHD - Map to a drive share.
MAPADMIN - Administer User Name Mapping for NFS (Network File System).
RMTSHARE - List or edit a file share or print share (on any computer).
RUNDLL32 - Add/remove print connections
SHARE - List or edit a file share or print share.
WMIC NETUSE - WMI access to drive mappings.
fsmgmt.msc - List or disconnect open files (GUI)
Equivalent PowerShell command: New-SmbMapping - Create an SMB mapping.
Equivalent bash command (Linux): lpc - line printer control program.


 
Copyright © 1999-2024 SS64.com
Some rights reserved