Permanently mount network share without the need for log on? (Windows)

This apparently possible, according to this StackOverflow post.

Before posting the content of the answer, however, can I suggest that you're over-complicating this?

In situations like this where some crappy piece of code needs a user logged on to run (like Domino server, grumble) I've created a service account that's to always be logged in on a given server, and setup an auto-login script, so that the machine logs in the specified account on reboot automatically. I'd suggest that the easier, and more supportable solution to your problem would be to do the same, and have the drive mapped for that service account user by Group Policy or logon script.

Anyway, should you be determined to try this without a user context, see the below. It's a hack, so use at your own risk and all:

For this hack you will need SysinternalsSuite by Mark Russinovich: http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

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 authority\system" 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: \servername\sharedfolder /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$.

From comments:

To get it working after a reboot, create a script just containing net use z: \servername\sharedfolder and set it to run on computer startup, per technet.microsoft.com/en-us/library/cc770556.aspx This will run as the SYSTEM account, so no need for psexec.


create its batch file, which runs this command. convert it to a windows service. make that service start at windows startup, and thats it.

It might be helpful: How to create a service running a .bat file on Windows 2008 Server?


You can also try adding Sysinternals Suite to C:\SysinternalsSuite

  1. Run an elevated cmd window
  2. cd c:\sysint*
  3. psexec -i -s cmd.exe
  4. whoami To make sure you are nt authority
  5. net use x: \\PathToDrive or share /persistent:yes

It should show as a disconnected drive and to automount it just create a startup script with step 5 in it. You will have to use steps 1 - 5 to delete the mapping just change 5 to reflect net use x: /delete


I found a solution to permanently mount a drive. However the drive is not mounted on every session. I did this on Windows Server 2019.

Let's say we want to mount a directory called target_dir located on target_server. My username is my_username and my password my_password on a domain called MY_DOMAIN. Let's mount it on the T: drive.

Firstly, create a new text file anywhere (on your Desktop for instance). Open it and parse this:

@ECHO OFF
net use s: \\target_server\target_dir /persistent:yes

Then, rename it to mount_drive.bat and move this file to C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup.

Be sure that the file is not a .txt file anymore.

Now, press Win+R, type gpedit.msc and run the Local Group Policy Editor.

Browse to Computer Configuration\Windows Settings\Scripts (Startup/Shutdown) and double-click on Startup.
Click on Add... then Browse..., select the file you have just moved.

Then browse to Computer Configuration\Administrative Templates\System\Logon, set Always wait for the network at computer startup and logon to enabled, save and close.

Open an elevated terminal to save your credentials. Then configure Windows in order not to disconnect this drive after a timeout.

cmdkey /add:target_server /user:MY_DOMAIN\my_username /pass:my_password
NET CONFIG SERVER /AUTODISCONNECT:-1

You can optionally verify everything works by running C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup\mount_drive.bat

Reboot