0

I'm using Directory.Exists(<path>) to check if a network/mapped drive is currently connected. I'm using the UNC Path which I get by reading the system's registry.

This works perfectly fine if I run my code through Visual Studio (it tells me that the directory does exist), but, it fails whenever I run the exact same code as a Windows service. I've checked the username and password of the service and it is the proper one needed - everything checks out.

I've also noticed that running Visual Studio as an admin return false while running as a normal user returns true. Does anyone have any idea as to what exactly is going on? I'm trying to get my program to behave the same whether I run it from Visual Studio or as a Windows service.

Roka545
  • 3,404
  • 20
  • 62
  • 106

1 Answers1

1

Its obvious your service doesn't see the network drive,

  • You need to run the Service under an Account that can see it, ie a Domain User, or a User with that share explicitly added
  • Or you need to use the direct IP Address in the path (Providing its set up with the right Permissions) i.e \\xxx.xxx.xx.xx\blah\blah

Note : in regards to the last option. Setting the Share Permissions is not enough. You will need to set the NTFS permissions appropriately

TheGeneral
  • 79,002
  • 9
  • 103
  • 141