7

As a rule of thumb Windows services can't access mapped drives and you have to use UNC paths instead.

I'm convinced that there's a way around this so that a Windows service can access a mapped drive but I can't find it anywhere.

My specific case is that I'm running Tomcat7 on a Windows 2008 server.

Edd
  • 409
  • 1
  • 5
  • 12

3 Answers3

17

An alternative to using mapped directories or UNC paths is to use symlinks.

NTFS symbolic links (symlinks) can refer to a UNC path but differ from shortcuts in that there is no redirect to the requested location. If you create a symlink as the following...

mklink /D C:\myLink \\127.0.0.1\c$

... then when you open C:\myLink the address of the folder you are in will be C:\myLink and not \\127.0.0.1\c$, which is what you would get if myLink was a shortcut and not a symlink. This is significant if your application has compatibility issues with UNC paths.

Additionally the symlink exists in the filesystem and does not need to be recreated after logon as your average mapped drive requires (generally automated) and is therefore available to Windows services.

Edd
  • 409
  • 1
  • 5
  • 12
3

I've found a solution to this problem that seems to be working nicely: https://stackoverflow.com/a/7867064/669645

Steps that I took:

  1. Create a bat file which contains the command net use z: \servername\sharedfolder /persistent:yes
  2. Create a scheduled task
    • Set user as "System"
    • Add an action to run the bat file
  3. Manually run the task (no need to set a schedule)

Note: the drive will appear as "Disconnected Network Drive (Z:)" but will still be accessible to all logged in users and also windows services

Edd
  • 409
  • 1
  • 5
  • 12
1

Just as an addendum to the excellent answers already provided, and as an answer to a question about using powershell, above, I would add that the Powershell equivalent of the accepted answer:

mklink /D C:\myLink \\127.0.0.1\c$

is this:

New-Item -Path C:\myLink -ItemType SymbolicLink -Target \\127.0.0.1\c$