On a Windows 2008 R2 Server (Standard) I need to have a network drive mounted without having a specific user to log on to the machine first. Sort of like an NFS
mount via fstab
on Unix machines. The network drive will be a share via a BlackArmor (Seagate) appliance (which I presume runs Samba). The appliance can be a member of the domain if needed.
So far I have tried using Edit Group Policy
-> Configuration
-> Windows
-> Scripts
-> Startup
where I had it execute
net use x: \\server\share /user:username password
With no success. Upon login the network drive was seen on Windows Explorer as a disconnected network drive.
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:
From comments:
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?
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 ontarget_server
. My username ismy_username
and my passwordmy_password
on a domain calledMY_DOMAIN
. Let's mount it on theT:
drive.Firstly, create a new text file anywhere (on your Desktop for instance). Open it and parse this:
Then, rename it to
mount_drive.bat
and move this file toC:\Windows\System32\GroupPolicy\Machine\Scripts\Startup
.Be sure that the file is not a
.txt
file anymore.Now, press
Win+R
, typegpedit.msc
and run the Local Group Policy Editor.Browse to
Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)
and double-click onStartup
.Click on
Add...
thenBrowse...
, select the file you have just moved.Then browse to
Computer Configuration\Administrative Templates\System\Logon
, setAlways wait for the network at computer startup and logon
toenabled
, save and close.Open an elevated terminal to save your credentials. Then configure Windows in order not to disconnect this drive after a timeout.
You can optionally verify everything works by running
C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup\mount_drive.bat
Reboot
You can also try adding Sysinternals Suite to C:\SysinternalsSuite
cmd
windowcd c:\sysint*
psexec -i -s cmd.exe
whoami
To make sure you are nt authoritynet use x: \\PathToDrive
orshare /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