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),
我有一个用。net c#开发的windows服务,使用VS 2010,我调用的是DriveInfo.GetDrives()但它没有Z: 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:
.
我在google上搜索了一下,发现了一些指向windows帐户特权的结果,所以我尝试了所有的服务安装程序,比如LocalSystem, User, LocalService, NetworkService,但是都没有工作,我仍然无法得到驱动Z:。
I did another test, debugging the windows service (as a console application) and I can get drive Z:
that way.
我做了另一个测试,调试windows服务(作为一个控制台应用程序),这样我就可以获得驱动器Z:那样。
Is there a solution to my problem?
我的问题有解决办法吗?
2 个解决方案
#1
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.
您需要使用一个具有网络驱动器映射的帐户来运行windows服务,例如,与您以前作为控制台应用程序运行的帐户相同。正如Hans所建议的,不应该在windows服务中使用映射驱动器,因为它们是与真实用户相关联的概念。
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
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).
驱动器映射与LUID关联,您可以在同一个用户(例如服务、正常的完整性级别、高的完整性级别等)下拥有多个身份验证ID。
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.
您可以在用户的会话中运行正常的完整性级别流程,以提供用户创建的映射驱动列表。这就是Windows资源管理器如何拷贝升级安装程序的驱动器。
#1
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.
您需要使用一个具有网络驱动器映射的帐户来运行windows服务,例如,与您以前作为控制台应用程序运行的帐户相同。正如Hans所建议的,不应该在windows服务中使用映射驱动器,因为它们是与真实用户相关联的概念。
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
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).
驱动器映射与LUID关联,您可以在同一个用户(例如服务、正常的完整性级别、高的完整性级别等)下拥有多个身份验证ID。
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.
您可以在用户的会话中运行正常的完整性级别流程,以提供用户创建的映射驱动列表。这就是Windows资源管理器如何拷贝升级安装程序的驱动器。