33

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.

3
  • 1
    Are you looking to have it available to anyone who logs in to that server, or does it need to be on a specific drive-letter for some system-service?
    – sysadmin1138
    Sep 11, 2012 at 11:39
  • 1
    I need it to be on a specific drive letter for use by applications that run as a service on the machine. I cannot have the service execute a "net use" upon starting up :(
    – adamo
    Sep 11, 2012 at 11:50
  • Have you tried editing the Local Computer Policy Settings and getting the script to run at start-up, from Computer configuration->Windows Settings->Scripts ?
    – thanosk
    Sep 11, 2012 at 12:03

4 Answers 4

25

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.

3
  • Using a network share with username and password this doesn't seem to work. I see the "Disconnected Network Drive" but am not able to access it "Wrong User Name and Password". Jun 20, 2014 at 14:19
  • 1
    @spankmaster79 <shrug> Not sure why you'd get that error (account lockout, maybe?), but if you have a new or related question, I'd recommend asking it as a question on the main site, instead of commenting here. Jun 20, 2014 at 14:30
  • Give me a short answer.
    – huang
    Dec 24, 2020 at 13:04
4

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?

1
  • seems like you took my word LITERALLY.. Do yo think a logon is required for windows service to run? i did a typo mistake, which i have corrected
    – Farhan
    Sep 11, 2012 at 12:15
3

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

2
  • What do you mean by "However the drive is not mounted on every session"?
    – Neoheurist
    Jun 21, 2020 at 15:00
  • I meant that the drive will only be available for the user specified in the command (in this example my_username)
    – vdsbenoit
    Sep 1, 2020 at 15:54
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .