- Remove From My Forums
-
Question
-
Hi,
Need to connect Map Network drive auto connection for all the users (once its mapped in administrator login)
Pls sugeest
Server : Windows 2012 R2
Workgroup
Regards,
Shahul Hameed
Answers
-
You could script it
net use e: /delete
net use e: \myservmyshareplaced in;
ProgramDataMicrosoftWindowsStart MenuProgramsStartUp
folder for all users.
Regards, Dave Patrick ….
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter ManagementDisclaimer: This posting is provided «AS IS» with no warranties or guarantees, and confers no rights.
-
Marked as answer by
Monday, February 5, 2018 5:11 AM
-
Marked as answer by
Map a network drive to get to it from File Explorer in Windows without having to look for it or type its network address each time.
-
Open File Explorer from the taskbar or the Start menu, or press the Windows logo key + E.
-
Select This PC from the left pane. Then, on the File Explorer ribbon, select More > Map network drive.
-
In the Drive list, select a drive letter. (Any available letter will do.)
-
In the Folder box, type the path of the folder or computer, or select Browse to find the folder or computer. To connect every time you sign in to your PC, select Reconnect at sign-in.
-
Select Finish.
Note: If you can’t connect to a network drive or folder, the computer you’re trying to connect to might be turned off, or you might not have the correct permissions. Try contacting your network administrator.
Map a network drive to get to it from File Explorer in Windows without having to look for it or type its network address each time.
-
Open File Explorer from the taskbar or the Start menu, or press the Windows logo key + E.
-
Select This PC from the left pane. Then, on the Computer tab, select Map network drive.
-
In the Drive list, select a drive letter. (Any available letter will do.)
-
In the Folder box, type the path of the folder or computer, or select Browse to find the folder or computer. To connect every time you sign in to your PC, select Reconnect at sign-in.
-
Select Finish.
Note: If you can’t connect to a network drive or folder, the computer you’re trying to connect to might be turned off, or you might not have the correct permissions. Try contacting your network administrator.
Suppose some Windows service uses code that wants mapped network drives and no UNC paths. How can I make the drive mapping available to the service’s session when the service is started? Logging in as the service user and creating a persistent mapping will not establish the mapping in the context of the actual service.
bluish
25.6k27 gold badges119 silver badges177 bronze badges
asked Oct 8, 2008 at 13:29
VoidPointerVoidPointer
17.4k15 gold badges54 silver badges58 bronze badges
1
Use this at your own risk. (I have tested it on XP and Server 2008 x64 R2)
For this hack you will need SysinternalsSuite by Mark Russinovich:
Step one:
Open an elevated cmd.exe prompt (Run as administrator)
Step two:
Elevate again to root using PSExec.exe:
Navigate to the folder containing SysinternalsSuite and execute the following command
psexec -i -s cmd.exe
you are now inside of a prompt that is nt authoritysystem
and you can prove this by typing whoami
. The -i
is needed because drive mappings need to interact with the user
Step Three:
Create the persistent mapped drive as the SYSTEM account with the following command
net use z: \servernamesharedfolder /persistent:yes
It’s that easy!
WARNING: You can only remove this mapping the same way you created it, from the SYSTEM account. If you need to remove it, follow steps 1 and 2 but change the command on step 3 to net use z: /delete
.
NOTE: The newly created mapped drive will now appear for ALL users of this system but they will see it displayed as «Disconnected Network Drive (Z:)». Do not let the name fool you. It may claim to be disconnected but it will work for everyone. That’s how you can tell this hack is not supported by M$.
bluish
25.6k27 gold badges119 silver badges177 bronze badges
answered Jan 21, 2011 at 20:11
17
I found a solution that is similar to the one with psexec but works without additional tools and survives a reboot.
Just add a sheduled task, insert «system» in the «run as» field and point the task to a batch file with the simple command
net use z: servernamesharedfolder /persistent:yes
Then select «run at system startup» (or similar, I do not have an English version) and you are done.
bluish
25.6k27 gold badges119 silver badges177 bronze badges
answered Oct 23, 2011 at 15:28
larrylarry
7695 silver badges2 bronze badges
9
You’ll either need to modify the service, or wrap it inside a helper process: apart from session/drive access issues, persistent drive mappings are only restored on an interactive logon, which services typically don’t perform.
The helper process approach can be pretty simple: just create a new service that maps the drive and starts the ‘real’ service. The only things that are not entirely trivial about this are:
-
The helper service will need to pass on all appropriate SCM commands (start/stop, etc.) to the real service. If the real service accepts custom SCM commands, remember to pass those on as well (I don’t expect a service that considers UNC paths exotic to use such commands, though…)
-
Things may get a bit tricky credential-wise. If the real service runs under a normal user account, you can run the helper service under that account as well, and all should be OK as long as the account has appropriate access to the network share. If the real service will only work when run as LOCALSYSTEM or somesuch, things get more interesting, as it either won’t be able to ‘see’ the network drive at all, or require some credential juggling to get things to work.
answered Oct 8, 2008 at 13:48
mdbmdb
51.4k11 gold badges64 silver badges62 bronze badges
1
A better way would be to use a symbolic link using mklink.exe. You can just create a link in the file system that any app can use. See http://en.wikipedia.org/wiki/NTFS_symbolic_link.
answered Oct 26, 2011 at 15:16
HalHal
4974 silver badges2 bronze badges
5
There is a good answer here:
https://superuser.com/a/651015/299678
I.e. You can use a symbolic link, e.g.
mklink /D C:myLink \127.0.0.1c$
answered Jun 3, 2016 at 2:38
philuphilu
7551 gold badge8 silver badges17 bronze badges
3
You could us the ‘net use’ command:
var p = System.Diagnostics.Process.Start("net.exe", "use K: \\Server\path");
var isCompleted = p.WaitForExit(5000);
If that does not work in a service, try the Winapi and PInvoke WNetAddConnection2
Edit: Obviously I misunderstood you — you can not change the sourcecode of the service, right? In that case I would follow the suggestion by mdb, but with a little twist: Create your own service (lets call it mapping service) that maps the drive and add this mapping service to the dependencies for the first (the actual working) service. That way the working service will not start before the mapping service has started (and mapped the drive).
answered Oct 8, 2008 at 13:38
TrebTreb
19.8k6 gold badges53 silver badges85 bronze badges
3
ForcePush,
NOTE: The newly created mapped drive will now appear for ALL users of this system but they will see it displayed as «Disconnected Network Drive (Z:)». Do not let the name fool you. It may claim to be disconnected but it will work for everyone. That’s how you can tell this hack is not supported by M$…
It all depends on the share permissions. If you have Everyone in the share permissions, this mapped drive will be accessible by other users. But if you have only some particular user whose credentials you used in your batch script and this batch script was added to the Startup scripts, only System account will have access to that share not even Administrator.
So if you use, for example, a scheduled ntbackuo job, System account must be used in ‘Run as’.
If your service’s ‘Log on as: Local System account’ it should work.
What I did, I didn’t map any drive letter in my startup script, just used net use \servershare ...
and used UNC path in my scheduled jobs. Added a logon script (or just add a batch file to the startup folder) with the mapping to the same share with some drive letter: net use Z: \...
with the same credentials. Now the logged user can see and access that mapped drive. There are 2 connections to the same share. In this case the user doesn’t see that annoying «Disconnected network drive …». But if you really need access to that share by the drive letter not just UNC, map that share with the different drive letters, e.g. Y for System and Z for users.
bluish
25.6k27 gold badges119 silver badges177 bronze badges
answered Jan 22, 2014 at 15:14
lk7777lk7777
1931 gold badge4 silver badges10 bronze badges
Found a way to grant Windows Service access to Network Drive.
Take Windows Server 2012 with NFS Disk for example:
Step 1: Write a Batch File to Mount.
Write a batch file, ex: C:mount_nfs.bat
echo %time% >> c:mount_nfs_log.txt
net use Z: \{your ip}{netdisk folder} >> C:mount_nfs_log.txt 2>&1
Step 2: Mount Disk as NT AUTHORITY/SYSTEM.
Open «Task Scheduler», create a new task:
- Run as «SYSTEM», at «System Startup».
- Create action: Run «C:mount_nfs.bat».
After these two simple steps, my Windows ActiveMQ Service run under «Local System» priviledge, perform perfectly without login.
answered Jan 20, 2016 at 9:13
ValVal
21.3k10 gold badges65 silver badges85 bronze badges
The reason why you are able to access the drive in when you normally run the executable from command prompt is that when u are executing it as normal exe you are running that application in the User account from which you have logged on . And that user has the privileges to access the network. But , when you install the executable as a service , by default if you see in the task manage it runs under ‘SYSTEM’ account . And you might be knowing that the ‘SYSTEM’ doesn’t have rights to access network resources.
There can be two solutions to this problem.
-
To map the drive as persistent as already pointed above.
-
There is one more approach that can be followed. If you open the service manager by typing in the ‘services.msc’you can go to your service and in the properties of your service there is a logOn tab where you can specify the account as any other account than ‘System’ you can either start service from your own logged on user account or through ‘Network Service’. When you do this .. the service can access any network component and drive even if they are not persistent also.
To achieve this programmatically you can look into ‘CreateService’ function at
http://msdn.microsoft.com/en-us/library/ms682450(v=vs.85).aspx and can set the parameter ‘lpServiceStartName ‘ to ‘NT AUTHORITYNetworkService’. This will start your service under ‘Network Service’ account and then you are done. -
You can also try by making the service as interactive by specifying SERVICE_INTERACTIVE_PROCESS in the servicetype parameter flag of your CreateService() function but this will be limited only till XP as Vista and 7 donot support this feature.
Hope the solutions help you.. Let me know if this worked for you .
Andro Selva
53.7k52 gold badges193 silver badges240 bronze badges
answered Sep 29, 2010 at 11:51
I find a very simple method: using command «New-SmbGlobalMapping» of powershell, which will mount drive globally:
$User = "usernmae"
$PWord = ConvertTo-SecureString -String "password" -AsPlainText -Force
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
New-SmbGlobalMapping -RemotePath \192.168.88.11shares -Credential $creds -LocalPath S:
answered Nov 26, 2021 at 6:22
lengxuehxlengxuehx
1,4501 gold badge18 silver badges25 bronze badges
5
You wan’t to either change the user that the Service runs under from «System» or find a sneaky way to run your mapping as System.
The funny thing is that this is possible by using the «at» command, simply schedule your drive mapping one minute into the future and it will be run under the System account making the drive visible to your service.
answered Oct 8, 2008 at 13:37
1
I can’t comment yet (working on reputation) but created an account just to answer @Tech Jerk @spankmaster79 (nice name lol) and @NMC issues they reported in reply to the «I found a solution that is similar to the one with psexec but works without additional tools and survives a reboot.» post @Larry had made.
The solution to this is to just browse to that folder from within the logged in account, ie:
\servernameshare
and let it prompt to login, and enter the same credentials you used for the UNC in psexec. After that it starts working. In my case, I think this is because the server with the service isn’t a member of the same domain as the server I’m mapping to. I’m thinking if the UNC and the scheduled task both refer to the IP instead of hostname
\123.456.789.012share
it may avoid the problem altogether.
If I ever get enough rep points on here i’ll add this as a reply instead.
answered Jun 6, 2016 at 19:16
Instead of relying on a persistent drive, you could set the script to map/unmap the drive each time you use it:
net use Q: \share.domain.comshare
forfiles /p Q:myfolder /s /m *.txt /d -0 /c "cmd /c del @path"
net use Q: /delete
This works for me.
mwfearnley
3,1172 gold badges31 silver badges35 bronze badges
answered Jan 26, 2018 at 20:57
1
What to Know
- Right-click This PC from File Explorer. Select Map network drive.
- Check Reconnect at sign-in to automatically remap the drive at each login.
- To map a network drive for all users, you need to create a special folder and script.
This article explains how to map a network drive in Windows 11, so you can easily access shared files from another computer on your network. We’ll also look at what the other computer must do to enable the share and what to watch for if you’re having issues mapping a network drive.
How to Map a Network Drive in Windows 11
It takes just a few steps to map a network drive via the This PC window.
-
Open File Explorer (WIN+E).
-
Right-click This PC from the left column, and select Map network drive.
If you don’t see anything in a left column, go to View > Show > Navigation pane.
-
Pick a letter from the menu you want the network drive to be identified as. This can be any letter in the list.
-
Browse for, or type the path to, the shared folder the network drive should be mapped to.
If the share requires a specific password, you should choose Connect using different credentials. You’ll be prompted to provide a username (and password) that has permission to access the other computer.
-
Select Finish.
You might have to wait a few seconds for Windows to establish the connection, after which you can access the share like you would a flash drive or local hard drive and rename how it appears in This PC.
If, after completing step 5, you get an error or a password prompt, see the tips at the end for more directions.
How to Automatically Map a Network Drive in Windows 11
The primary way to set up an automatic network drive is to follow the steps above and choose Reconnect at sign-in during setup. This will make the same network drive resume the next time you sign on.
If you’re managing several computers at once, or even one computer with several users, and you need to map the network drive on all of them, automatically, there’s a script you can build to get the job done. The same method works for creating the network drive for other users on a local computer; see the steps below for instructions.
How to Map a Network Drive in Windows 11 for All Users
Mapping a network drive for all users at once is much easier than following the above steps individually under each account. Follow these steps whether you’re a network admin that needs to perform this trick across your entire network of computers, or you want the local accounts on your PC to be able to reach the same shared files with ease.
-
Use the net use command to create a script that will auto-connect the mapped network drive.
Here’s an example, where the driver letter will be assigned automatically, and the connection to the share (serverfiles, in this example) will persist (/p:yes) each time the user logs in:
net use * "\serverfiles" /p:yes
The script needs to be saved as a BAT file so Windows will execute it when the user logs in.
Visit the net use command link above for examples of embedding credentials in the command. It’s necessary if the computer sharing the files requires a password.
-
Open the All Users Startup folder. One easy way to find it is to run this command in the Run dialog box (WIN+R):
shell:common startup
-
Copy the BAT file from step 1 into the folder you uncovered in step 2.
Now, when any user logs in on that computer, the network drive you set up in the script will automatically connect.
Troubleshooting Mapped Network Drives
A few things must be in place before network sharing is allowed in Windows 11.
If you’re sure your computer is on the same network as the one sharing the files (that’s a necessity), keep these things in mind if you’re having trouble mapping a network drive or using it once you’ve mapped it:
Network Discovery
Network discovery lets you see network computers and their shares. Make sure it’s turned on in Control Panel.
-
Open Control Panel, and navigate to Network and Internet > Network and Sharing Center > Change advanced sharing settings.
-
Expand the section that says current profile, and select Turn on network discovery.
The computer doing the sharing (i.e., the one you’re attempting to connect to) needs to have selected Turn on file and printer sharing from this same screen before they can share with you over the network.
-
Select Save changes, and then try again to map the network drive.
Password-Protected Sharing
You must either have the login credentials for the user sharing the files with you, or their computer needs to be set up to allow sharing even if a password isn’t provided.
In the All Networks section, they can set up the latter by selecting Turn off password protected sharing via the same screen as above.
Share Permissions
You can configure the share to allow a certain number of users simultaneously. It can even be limited to viewing the files only, meaning you can’t edit or add anything to the network drive. To be given these permissions, the person managing the network share must make changes from their side.
If they access the Sharing tab of the folder’s properties, the Advanced Sharing button is an option to limit how many users can be utilizing the share at once. On that same screen, in the Permissions area, the manager of the files can give you complete control or edit access.
Full Share Path
Make sure you’re accessing the true path to the share. Typing the path manually when setting up the network drive can result in a mistake. You can obtain the share path from the computer sharing the resources.
Open File Explorer and navigate to Network from the navigation pane on that computer. Open the computer name you see there, and then find the folder you want to access. That’s the path you need to enter into your computer to complete the mapped drive.
The same path is accessible from the folder itself. Right-click it, go into the Sharing tab and copy the text from the Network Path area.
FAQ
-
How do I unmap a network drive in Windows 11?
Right-click This PC from File Explorer, and choose Disconnect network drive. Choose the drive you want to disconnect, then choose OK.
-
How do I reconnect to a network drive in Windows 11?
If you’re having trouble connecting to a network drive, disconnect the drive and then re-map it. When mapping the drive, make sure Reconnect at sign-in is selected.
-
How do I share network files in Windows 11?
Aside from mapping a network drive, there are other network file sharing options in Windows 11. These include sharing files in the cloud with OneDrive, Windows public folder sharing, and third-party sharing solutions.
Thanks for letting us know!
Get the Latest Tech News Delivered Every Day
Subscribe
While users can easily create a shortcut for the network share in Windows 10, they have to access the shortcut every time they need to open the network share. A better solution for accessing files from the network is to map a network drive so that it appears in Computer and File Explorer as a Drive instead of the folder.
In this article, we will discuss how to map a network drive successfully and easily using Windows File Explorer and command-line. You can use it any way you are easy with. This article also answers the following queries:
- How to map a network drive in Windows 10
- How to automatically map a network drive upon computer restart
- How to map a network drive for all users
- How to map a network drive using GPO, PowerShell, and File Explorer
Mapping a network drive using File Explorer
To make sure that you are connected to the network where the shared folder exists and is accessible, look at the image provided below for your reference.
Now that we have ensured that the network folder is visible to which we want to assign a drive letter so that we can proceed towards mapping the network location as a drive.
Step 1: Open File Explorer with the right options
Open File Explorer and go to ‘This PC’ on the left top corner below the title bar in the menu bar and select the computer tab from the network section.
Step 2: Open network drive creation wizard
Select “Map Network Drive” and a wizard will appear.
Here Select the drive letter from the available drop-down menu and you can either type in the correct address of the shared network folder by yourself or you can browse it.
Press OK and keep ‘Reconnect at sign-in’ checked as this will connect the drive automatically at startup. Click Finish.
Step 3: Using different user credentials
If you have a different username and password for the folder you are accessing you should also keep the ‘Connect using different credentials’ checked.
Once you press finish it will ask for the password and username first you need to enter the name of the network location as shown in the image below then type the username followed by ‘backslash()’
Type the password and it’s done.
Map a network drive using PowerShell
You can also do this using the PowerShell 3.0 here is the equivalent command in PowerShell for what we did in the explorer:
New-PSDrive -Name P -PSProvider FileSystem -Root “\Server01Public” -Credential userdomain -Persist
After the ‘Name’ flag you may write the desired the drive letter you want to assign we have assigned ‘Z’ in our example
The ‘Credential’ flag is equivalent to checking the ‘connect using different credentials’ option. If you skip this option you won’t get the last prompt that has been shown in the small windows asking for the username and password.
The ‘Persist’ flag is equivalent to checking the ‘Reconnect at sign-in’ in the explorer. You can find your username from the settings>Accounts>Your info here the one that is hidden with the purple box is your username.
Your password is the one that you use to log in the computer however it should not be the pin that windows 10 provides to make logins quicker.
You can find your domain from the system properties. The name after the full computer name is what your computer will be using it as a domain name in the network.
Mapping a network drive for all users
This method will work for only one PC having multiple users.
Create a batch file with the following commands in it:
net use Z: /delete net use Z: "\DESKTOP-FK154L3softwares" /user:DESKTOP-FK154L3pavilionhp VMware
Here “Z” is the drive we are going to map after that it has the address of the location that I want to map “DESKTOP-FK154L3” which is my domain, pavilionhp is my username and vmware is my password. Copy the second line and paste into the cmd to see if it works
Now save the text file you just created rename it to whatever you like and make its extension from “.txt” to “.bat”(more on this at the end of the article). Your final text file should like the one shown in the image above.
C:ProgramDataMicrosoftWindowsStart MenuProgramsStartU
Paste the above-mentioned address in the address bar of My computer and paste the newly created bat file into it. You may face issues browsing the directory directly as it is a hidden directory so you should stick with copy-pasting the address into the address bar. That’s it now every time the PC starts, it will make the mapping of this remote directory on to this computer for all the users that login to it.
In the end, you can use either of the methods both works flawlessly given that you don’t mess up the credentials and give the right path. You can use the one with which you are comfortable with. Mapping a network folder does give us a handy shortcut as explained above however you should at least notify your IT department of the mapped folder if you are using this feature in an organization though there aren’t any issues that a typical home user will face using this functionality.
This feature is most useful when you have configured a network drive with your router so you can map it as a drive in other computers saving others through the difficulty of understanding the complexity. There are also some 3rd party applications that give the same facility but it is a total no brainer to use a third party app if the available options in the Windows already work well.
Also see:
Itechtics staff is a team of technology experts led by Usman Khurshid. We verify everything we write so that our users can be sure to trust us in everything we write. You can reach out to us for further help and support.
This article will focus on another way to map a network drive on your computer instead of from the explorer interface method. You will learn to map network drive using cmd (command line) along with “net use” where you can include also user password. Not only but an article with explain also how to create a batch file to map network drive and to automate this process on your computer or in the all network.
Read Also: Unmap network drive using cmd
Map Network Drive Command Line
How to map network drive using cmd commands “net use”
You can map a network drive from different ways but the cmd is like a “professional” way. The universal command for the Windows operating system to map network drive from cmd is “net use”. To map a network drive using T as the drive letter and without username password-protected, use the following guide:
- Connect to a command prompt by clicking on start and search for cmd.
- Right-click and open as “Run as administrator”.
- Copy-paste the below command and click Enter:
net use T: \networkShareTest
Note! Check the file explorer and the Map Drive “T” will appear there.
Map network drive cmd
Net use with username and password
The above command will work and completes successfully without asking the user to provide a username/password if the user has authorized access to this network share. But if not? Is simple, you will need to use username and password on the prompt that will appear. Keep remembering that the user needs to have access to the share. But the easy way is to use the “net use” command on the command prompt line explained above.
- Open again the command prompt with “Run as administrator”
- Edit the command below with you username password
- Copy-paste into CMD and click Enter:
net use T: \networkShareTest /u:domainnameusername password
Tip! Use “*” instead of the letter so in this way the system will use automatically an unused drive letter.
Most people now days like to avoid plain text and for this, you can specify only the username. The command prompt will ask you for the password.
net use T: \networkShareTest /u:domainnameusername
net use – username password
Batch file to map network drive with username and password
What if you need to automate the creation of network drive? The batch file comes to help you in this situation where you can schedule that or to configure on GPO. In this way, you war automate the creation of network drive on your network devices. Let’s check how to create a batch file to map network drive with username and password:
- Open a notepad file
- Type @echo Create new T: drive mapping
- Type “net use T: \networkShareTest path /persistent:yes”
- Type: exit
- Save the file as name.bat file
- Automate this bate file with your automation tools.
- Check this post to automate it on task scheduler
@echo Create new T: drive mapping net use T: \networkShareTest path /persistent:yes :exit
Tip! If you want to map multiple drives just keep repeating steps 2 and 3. Change the later and the path if it is different.
Tip!! Use “/u:domainnameusername password” command in the script to include username password.
Map system drive (C:) of remote computer
What if you need to map a drive form a computer on the network that you have administrator access? Yes is simply easy just you need to change a part of the net use command:
net use T: \testpcD$ /u:username password
Net use persistent
Mapped drives are not persistent by default and to do that you need to use some cmd commands. By default, if we use the command above to map drive the mapped drive would disappear after you restarted the computer. So make them persistent by using the /persistent switch.
/persistent:Yes: The connection that you’re currently creating will be persistent. Also, future connections during the same session will be also persistent. So you don’t need to keep using the /persistent: Yes command until you use the /persistent: No switch to turn it off.
/persistent:No: Turns off the persistency toggle. Future connections will not be persistent until you turn the toggle back on.
net use T: \networkShareTest /u:domainnameusername password /persistent:yes
net use persistent
Map a network drive using PowerShell
Relevant automation as CMD is also the PowerShell. The PowerShell commands differ from cmd commands so below we will explain the equivalent command:
New-PSDrive -Name T -PSProvider FileSystem -Root “\networkShareTest” -Credential userdomain –Persist
-Name – Write the desired drive letter you want to assign. In the example is assigned ‘T’.
-Credential – Is equivalent to checking the ‘connect using different credentials’ option. If you skip this option you won’t get the prompt asking for the username and password.
–Persist – equivalent to checking the ‘Reconnect at sign-in’ in the explorer.
To find the domain open system properties. The name after the full computer name is a domain name in the network.
map network drive PowerShell
Mapping a network drive for all users
What if you have multiple users on the PC and you need to create automatically a certain map drive for all users? In this case, the below solution will help you.
- Open a notepad file
- Type @echo Delete T: drive if exist
- Type net use T: /delete
- Type @echo Create T: drive
- Type net use T: \networkShareTest ” /u:domainnameusername password
- Type :exit
- Save the file as AutoMapDrive.bat file
- Copy the bat file to “C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUp”
- Every time the PC starts will map the remote directory onto this computer for all the users that login to it.
net use T: /delete net use T: \networkShareTest " /u:domainnameusername password
Conclusions
This is all about Map Network Drive using cmd and batch file with help of net use user password commands. Let’s hope that our solutions help you to automate everyday jobs.
I had the same problem where a Bulk Copy Job (BCP) on SQL Server needed to write a file out to a different server, managed by a different group in the organization.
The trick is to get the drive mapped as the user that the BCP job is using.
You map the drive as a dedicated active directory account that has permissions for the desired destination, what some call a service account. I had to work with my AD folks to get one setup.
To find out what user account is being used by BCP run this command from a SQL Server Query window:
EXEC xp_cmdshell 'ECHO %USERDOMAIN%%USERNAME%
When mapping the drive, use whoami
at the command prompt.
In my case, I was unable to be logged into the SQL Server as the SYSTEM account, so I built a batch job that could then be executed by Task Scheduler, but run AS the SYSTEM account.
I put commands in the batch job to write the results out to a text file, since I wouldn’t be able to see it.
** Batch job below **
ECHO ON
ECHO This will map the drive, but is being run by task scheduler AS the user SYSTEM
ECHO which should make it accessible to the user SYSTEM
ECHO List the existing drives first.
net use >> c:TestSystemNetUseOutput.txt
net use R: \MyRemoteServerMyDirectory /P:Yes /u:MyDomainMyUsername pa$$word
ECHO the /P switch makes the drive remain after reboot
ECHO List the existing drives with the new mapping
net use >> c:TestSystemNetUseOutput.txt
ECHO See what user this batch job ran under
whoami >> c:TestSystemNetUseOutput.txt
ECHO need to exit to allow the job to finish
EXIT
** I hope this helps someone else **
Mapping a Network Drive on Your Windows 10 PC
- Press Win + E to open a File Explorer window.
- In Windows 10, choose This PC from the left side of the window. …
- In Windows 10, click the Computer tab.
- Click the Map Network Drive button. …
- Choose a drive letter. …
- Click the Browse button.
How do I automatically map a network drive?
How to Map a Network Drive in Windows 10
- Open File Explorer and select This PC.
- Click the Map network drive drop-down in the ribbon menu at the top, then select “Map network drive.” (This is under the Computer tab, which should open automatically when you go to This PC, as above.)
How do I map a public drive?
Map a network drive in Windows 10
- Open File Explorer from the taskbar or the Start menu, or press the Windows logo key + E.
- Select This PC from the left pane. …
- In the Drive list, select a drive letter. …
- In the Folder box, type the path of the folder or computer, or select Browse to find the folder or computer.
Right click on the Computer icon on the desktop. From the drop down list, choose Map Network Drive. Pick a drive letter that you want to use to access the shared folder and then type in the UNC path to the folder. UNC path is just a special format for pointing to a folder on another computer.
How do I access a network drive?
Click the Start menu. Click File Explorer. Click This PC in the left side shortcut menu. Click Computer > Map network drive > Map network drive to enter Mapping wizard.
Why can’t I map a network drive?
When getting this specific error trying to map a network drive, it means that there is already another drive mapped to the same server using a different username. … If changing the user to wpkgclient does not resolve the issue, try setting it to some of the other users to see if that resolves the issue.
How do I copy a full path of a mapped drive?
Any way to copy a full network path on Windows 10?
- Open Command Prompt.
- Type net use command and press Enter.
- You should now have all mapped drives listed in the command result. You can copy the full path from the command line itself.
- Or use net use > drives. txt command and then save the command output to a text file.
How do I reconnect a network drive?
Select a Drive letter and a Folder path.
- For Drive: select a drive not already in use on your computer.
- For Folder: your department or IT support should provide a path to enter in this box. …
- To connect automatically each time you log in, check the Reconnect at logon box.
- Check Connect using different credentials.
How do I find the path of a mapped drive?
On the command terminal, please then type the following: “net use”. 4 . Once this is entered, it will show you a full list of all the network drives mapped. This output will have the full network paths for any of the mapped network drives.
If you frequently need to connect to a remote folder or a drive shared on your network, mapping the drive or the folder location on your Windows 11 PC will save you a big chunk of time. Plus, the entire experience of using a mapped network drive feels identical to using any other drive plugged into your PC.
If all of this sounds perfect to you, let’s quickly take a look at how you can map a network drive on Windows 11.
Before we begin with the steps, you need to make sure that Windows 11 is configured to find other PCs and devices on your network.
First, configure Windows for Network drives
Click the Start button and type in ‘Control Panel’. Click on the search result or the open button.
Once inside Control Panel, click on ‘Network and Internet’.
Click on ‘Network and Sharing Center’.
Click on ‘Change advanced sharing settings’.
Click on ‘Turn on network discovery’ and then click the ‘Save changes’ button. Accept any prompt that may appear.
After this change, your PC should be able to find your network folder or drive and be discoverable by other PCs and devices on your network.
It’s time to map the drive to your Windows 11 PC.
5 Ways to map a drive on Windows 11
Once you have configured your Windows 11 PC for mapping as given above, you can now go ahead and map a drive on your PC. Here are various methods to map a drive on Windows 11 OS.
Method 1: Using File Explorer
Head over to ‘This PC’ by pressing the Win key + e
buttons. From the Quick Access window, click on the shortcut for ‘This PC’.
The next step is to click on the three-dot menu and from this list of options, select ‘Map a network drive’.
You should see a popup titled ‘Map Network Drive’. On this popup, select your preferred drive letter for the remote location, enter the URL of your network folder and click ‘Finish’. You can also click on the ‘Browse’ button and select the shared folder.
Tips
- If you want Windows to automatically reconnect to the network folder after boot, tick the ‘Reconnect at sign-in’ option.
- If you use a different set of login credentials to access your shared folder or drive than your PC, tick the ‘Connect using different credentials’ option. Windows should ask for the username and password when it attempts to connect to the remote location. Tick the ‘Remember my credentials’ to save your credentials, instead of entering them every time you connect.
After verifying the credentials, Windows should open the remote folder right away.
You should be able to find the newly added network location in your ‘This PC’ window.
That’s it! You have successfully mapped a network location to your Windows PC.
Another, rather simpler way to connect to the shared drive is to navigate to the shared network drive or folder in File Explorer, and then use the context menu to map it as a drive on your PC.
There are a couple of ways that you can access the shared drive via File Explorer. First up, press Win+E
to open File Explorer. Now click on Network in the left pane.
Select the system that’s sharing the drive by double-clicking on it.
Then right-click on the folder or the drive to map and select Map network drive…
The familiar ‘Map Network Drive’ window will open up. Select the drive letter for the mapped drive, and then click on Finish to map the drive.
Your drive/folder will now be mapped and available on the ‘This PC’ page.
If you know the IP address of the system that’s sharing the drive, then you can simply click on the address bar and type the IP address in the following format:
\IP_address
Make sure to change IP_Address with the IP address of the sharing network.
Then right-click on the drive/folder that you want to map and select Map network drive as shown above.
If you want to check the folders that are shared by you, you can either enter your own IP address or type 127.0.0.1 instead (which directs to the local host).
Method 3: Using CMD
You can also map a drive in Windows 11 via the CMD. Use the guide below to get you started.
Press Windows + S
on your keyboard and search for CMD. Click on ‘Run as administrator’ once it shows up in your search results.
Enter the following command and press Enter on your keyboard. Replace ‘DLetter’ with the drive letter of your choice and replace ‘PATH’ with the path to the particular folder you wish to map.
net use DLetter: \PATH /PERSISTENT: YES
The selected drive will now be mapped within Windows 11 and it should now show up in the File Explorer.
Method 4: Using PowerShell
Use the guide below to easily map a drive within PowerShell instead.
Press Windows + S
on your keyboard and search for PowerShell. Click on ‘Run as administrator’ once it shows up in your search results.
Now type in the following command and press Enter on your keyboard to execute it. Replace DLetter with the assigned letter of the concerned drive and replace PATH with the path to the folder you wish to map.
New-PSDrive -Name "DLetter" -PSProvider "FileSystem" -Root "\PATH" -Persist
The selected drive and location should now be mapped within Windows 11. Open the File Explorer and the drive should now appear within This PC.
Method 5: Map a drive for all users at once
If there are multiple users on your computer that also require access to the shared drive, it’s much more convenient to map a drive for all users at once. To do so, we’ll first have to create a batch (.bat) file. Here’s how to do so:
Press Start, type notepad, and then open it.
Then type the following command:
net use * "\serverfiles" /p:yes
Make sure to replace ‘server’ with the network name or the IP address of the user who’s doing the sharing, and ‘files’ with the folder, drive, or file that you want to map.
Then click on File in the top left corner.
Select Save as.
Choose a location to save and give the file a name. Then change the file extension from .txt to .bat.
Then select All files from the “Save as type” drop-down menu.
Then click on Save.
Once saved, go to the location and copy this .bat file.
Now, press Win+R
to open the RUN box. Now type the following:
shell:common startup
And click OK.
This will open the startup apps folder. Paste the .bat file here by pressing Ctrl+V
, or right-clicking and selecting the Paste button.
When prompted, click on Continue.
From now on, whichever user logs on to your system will automatically connect to the network drive as mentioned in the script.
How to find the path of a mapped network drive
You can easily get the full UNC path to your mapped network drive using one of the guides below. Follow the one that best suits your current needs to get you started.
Method 1: Using CMD
Press Windows + S
on your keyboard and search for CMD. Click on run as administrator once it shows up in your search results.
Enter the following command and press Enter on your keyboard.
net use
You will now get a list of all the network devices connected to your PC for the current user account. Your mapped network drive will also show up in this list, with its full UNC path mentioned on your screen.
Method 2: Using PowerShell
Press Windows + S
on your keyboard and search for PowerShell. Click on ‘Run as administrator’.
Now enter the following command and press Enter on your keyboard to execute it.
Get-WmiObject Win32_NetworkConnection | ft "RemoteName","LocalName" -A
All the network drives currently accessible through your PC and user account should now be available on your screen with their UNC paths as well.
How to disconnect a Mapped Network Drive
Once your business with the shared network drive is finished, you should disconnect and unmap the network drive. Doing so is a cinch. Here’s how to go about it:
Method 1: Using File Explorer
Open File Explorer by pressing Win+E
. Right-click on the mapped drive and select Disconnect.
Alternatively, click on the three-dot icon in the toolbar above.
Then select Disconnect network drive.
Then select the mapped drive and click OK.
The network drive will now be unmapped.
Method 2: Using CMD
Open an elevated instance of the command prompt.
Then type the following command:
net use z: /Delete
Replace ‘z’ with the network drive’s letter.
Then press Enter
If you have multiple drives mapped, type the following to disconnect them all:
net use * /Delete
Then hit Enter.
Quick tip: If you get an error message saying that “There are no entries in the list”, try running the command prompt without administrator privileges.
When prompted, type Y.
Then hit Enter.
Your mapped network drive will now be deleted. You can use these commands in the PowerShell terminal as well. Also, if you aren’t receiving any entries with the elevated PowerShell, try running PowerShell without administrator privileges.
I am unable to map a network drive in Windows 11
There is a common registry fix that seems to get network drives working on almost every system no matter the issue that you are facing.
Map a drive first using any of the methods given above. When that is not working, use the registry editor fix given below.
In the guide below, we talk about creating a new registry value on your PC that should help you easily map network drives without any issues.
Press Windows + S
on your keyboard and search for Regedit. Click and launch the app once it shows up in your results.
Navigate to the following path given below. You can also copy-paste the same in your address bar at the top.
ComputerHKEY_CURRENT_USERNetwork
Your drive should be listed under ‘network’ denoted by its drive letter. Click and select the drive letter folder and hit delete on your keyboard.
Click on ‘Ok’ to confirm your choice.
Navigate to the following path given below.
HKEY_CURRENT_USERSOFTWAREMicrosoftWindowsCurrentVersionExplorerMap Network Drive MRU
The registry values you find for mapped network drives in this location will be different depending on your system, configuration, and mapped drive. Find any string value associated with the previously mapped drive on your system and hit delete on your keyboard. Click on ‘Ok’ to confirm your choice and delete these values.
All previous registry values that could conflict with your current setup should now be removed. Simply restart your system and use one of the guides above to map a network drive to your system again.
Once done, launch registry editor again and navigate to the path given below. Replace DLetter with the drive letter of the drive you recently mapped to your PC.
HKEY_CURRENT_USERNetworkDLetter
Click and select the drive letter on your left and now right-click on the empty area on your right and select ‘New’.
Now select ‘DWORD (32-bit) value’.
Enter ‘ProviderFlags’ as the ‘Value Name’ and set the ‘Value data’ to ‘1’.
Click on ‘Ok’ now.
Restart your system for good measure.
And that’s it! The selected drive should now be mapped to your system without any issues.
Have a question? Let us know in the comments below.