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
My username is
my_username and my password
my_password on a domain called
Let's mount it on the
Firstly, create a new text file anywhere (on your Desktop for instance). Open it and parse this:
net use s: \\target_server\target_dir /persistent:yes
Then, rename it to
mount_drive.bat and move this file to
Be sure that the file is not a
.txt file anymore.
gpedit.msc and run the Local Group Policy Editor.
Computer Configuration\Windows Settings\Scripts (Startup/Shutdown) and double-click on
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