5

I have a windows service developed in .NET C# using VS 2010, I'm calling the DriveInfo.GetDrives() but it is not getting the Z: drive (a mapped network drive),

I did some googling and found some results pointing to windows account privileges, so I have tried all account types of service installer such as LocalSystem, User, LocalService, NetworkService but none worked and I still can't get the drive Z:.

I did another test, debugging the windows service (as a console application) and I can get drive Z: that way.

Is there a solution to my problem?

João Angelo
  • 51,934
  • 12
  • 129
  • 140
khaled jendi
  • 61
  • 2
  • 5
  • 8
    Drive mappings a per-user setting. The service probably is running with a different user account. Don't use mapped drive letters in a service. – Hans Passant Aug 19 '12 at 20:47

2 Answers2

6

You need to run the windows service with an account that has the network drive mapped, for example, the same account that you used to run as a console application. As Hans advised you should not be using mapped drives in windows services because they are a concept associated to a real user.

However if you really want to continue to use mapped drives see this related question for pitfalls and workarounds related to this specific situation:

How to map a network drive to be used by a service

Community
  • 1
  • 1
João Angelo
  • 51,934
  • 12
  • 129
  • 140
2

Drive mappings are associated with LUID and you could have multiple Authentication ID under the same user (e.g. service, normal integrity level, high integrity level etc).

You can have a normal integrity level process running in the user's session to provide the mapped drive list created by the user. This is how Windows Explorer copies mapped drives for elevated setup programs.

Sheng Jiang 蒋晟
  • 14,859
  • 2
  • 26
  • 44