Why does DriveInfo.GetDrives() not get network mapped drive in windows service

牧云@^-^@ 提交于 2021-02-07 14:51:17

问题


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?


回答1:


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




回答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.



来源:https://stackoverflow.com/questions/12029855/why-does-driveinfo-getdrives-not-get-network-mapped-drive-in-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!