Windows服务连接到另一个域上的UNC路径. [英] Windows service connecting to UNC path on another domain.

查看:114
本文介绍了Windows服务连接到另一个域上的UNC路径.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这是我的问题:

我正在用C#编写Windows服务应用程序(它必须是非常规应用程序的服务),该应用程序将在Web服务器上运行.
该服务然后将需要连接到存储在不同域(但在同一LAN上)的计算机上的数据. UNC路径,域名,用户名和密码对于应用程序都是已知的.

这是到目前为止我尝试过的操作:

1)使用WNetAddConnection2将UNC路径映射到盘符.在某种程度上可以工作,该驱动器似乎可以正常映射,但是当尝试在该驱动器上实际执行任何操作(例如访问文件)时,我收到访问被拒绝的错误.
我也遇到了这种方法的问题,因为已映射的驱动器

2)我的服务在本地系统"下运行.帐户,经过一番搜索后,我发现它需要在网络服务"下运行.查看任何网络资源.不幸的是,当我尝试此操作时,我不断收到错误5:访问被拒绝"消息.尝试启动服务时.

我尝试设置我的设置,以允许该帐户完全访问所有内容,但没什么区别.

3)在MSDN库中进行了更多挖掘之后,我发现这:一点点的智慧:

服务不应通过以下方式直接访问本地或网络资源 映射的驱动器号.此外,服务不应使用Windows网络 管理映射驱动器号的功能.服务(或任何 在不同的安全上下文中运行的进程)必须访问远程 资源应使用通用命名约定(UNC)名称来访问 资源."

问题在于我无法使用UNC路径直接访问此资源,因为我不在同一域中.

文章继续说:尽管WNet函数可能会成功返回,结果是 因此,对于我的问题:

A)有人知道如何使用网络服务"来运行此服务吗?帐户.
B)如何枚举系统上的所有驱动器-包括网络共享.

Hi all, here's my problem:

I am writting a windows service application in C# (It must be a service not a normal app) that will be running on a web server.
This service will then need to connect to data stored on a machine in a different domain (but on the same LAN). The UNC path, domain name, user name and password are all known to the application.

Here's what I've tried so far:

1) Using WNetAddConnection2 to map the UNC path to a drive letter. Works to some extent, the drive seems to map ok but when trying to actually do anything (like access the files) on the drive I get an access denied error.
Also I have problems with this method because drives that are already mapped do not show up in DriveInfo.GetDrives().

2) My service was running under the "local system" account and after some searching I found that it needed to be running under "network service" to see any network resources. Unfortunatley when I try this I keep getting "Error 5: Access denied" when trying to start the service.

I tried setting my settings to allow this account full access to everything but it made no difference.

3) After some more digging in the MSDN library I found this: little nugget of wisdom:

"A service should not directly access local or network resources through mapped drive letters. Additionally, a service should not use the Windows Networking Functions to manage mapped drive letters. A service (or any process running in a different security context) that must access a remote resource should use the Universal Naming Convention (UNC) name to access the resource."

The trouble is I can't access this using the UNC path directly because I'm not on the same domain.

The article goes on to say: "Although the WNet functions may return successfully, the resulting behavior is not as intended."


So, to my question(s):

A) Does anyone know how to run this service using the "Network Service" account.
B) How can I enumerate ALL drives on the system - including network shares.

推荐答案

只是以为这应该是不同的论坛...也许是Windows编程还是某事?

我还是看不到,所以如果这是在错误的地方,有人让我知道;)
Just thought maybe this should be in a different forum... maybe windows programming or somthing?

I can't see one though so if this is in the wrong place someone just let me know ;)


这篇关于Windows服务连接到另一个域上的UNC路径.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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