问题
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