为什么DriveInfo.GetDrives()无法在Windows服务中获取网络映射的驱动器 [英] Why does DriveInfo.GetDrives() not get network mapped drive in windows service

查看:57
本文介绍了为什么DriveInfo.GetDrives()无法在Windows服务中获取网络映射的驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用VS 2010在.NET C#中开发的Windows服务,我正在调用 DriveInfo.GetDrives(),但是没有获得 Z:驱动器(映射的网络驱动器)

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),

我做了一些谷歌搜索,发现了一些指向Windows帐户特权的结果,因此我尝试了所有帐户类型的服务安装程序,例如LocalSystem,User,LocalService,NetworkService,但没有任何作用,但是我仍然无法获得驱动器 Z:.

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:.

我进行了另一项测试,调试了Windows服务(作为控制台应用程序),这样我就可以得到驱动器 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?

推荐答案

您需要使用已映射网络驱动器的帐户(例如,与用作控制台应用程序时使用的帐户相同)运行Windows服务.正如Hans所建议的那样,您不应在Windows服务中使用映射驱动器,因为它们是与真实用户相关联的概念.

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:

如何映射网络服务使用的驱动器

这篇关于为什么DriveInfo.GetDrives()无法在Windows服务中获取网络映射的驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆