c# - 模拟服务和网络位置的问题

标签 c# .net windows service impersonation

我有一个Windows服务,该服务对新文件进行了调查。选择网络位置(同一网络上的远程计算机上的文件夹),我会查询用户对远程计算机的用户名和密码(有权访问该文件夹的用户),我对其进行验证并将其存储到服务的注册表中。这种方法工作正常。(服务服务作为本地计算机运行并使用模拟代码)。 p>

但是有些场景我没有意识到..

1. 直接连接到网络的无线硬盘驱动器/存储设备。目前我使用模拟代码来提供用户凭据。在这种情况下,作为本地机器运行的服务可以直接访问驱动器?

2.如何处理有权访问该文件夹的域用户?

我正在使用以下代码来模拟用户

https://stackoverflow.com/a/9213965/848968

UserImpersonation impersonator = new UserImpersonation();
impersonator.impersonateUser("username", "", "password"); //No Domain is required

域用户怎么办?

最佳答案

  1. Wireless HDDs /Storage devices that are directly connected to the network.Currently i use impersonation code to supply user credentials.In such scenarios will the drive be directly accessible to the service running as localmachine?

驱动器是如何连接的?如果它的 SMB 通过 UNC 路径,那应该没问题。当您进入映射驱动器时,Windows 服务无法使用这些驱动器。

  1. How to deal with Domain Users who has access to the Folder?

impersonator.impersonateUser("用户名", "域", "密码");

您可能还想查看 this answer有关更多模拟信息和示例代码。有一个很棒的库可以为您整理这些内容。

关于c# - 模拟服务和网络位置的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52263669/

相关文章:

c# - 不能在 LINQ 查询中使用三元运算符

c# - 全局资源未将样式应用于 xaml 中的控件

c# - 组合 URI 和路径

arrays - 在 Windows 批处理文件中循环

windows - 如何在 DB2 表上写入数据阶段性能统计信息?

windows - gitstats在windows中使用gitstats报错的解决方法

c# - ASP.NET 5 MVC6 错误 : project is not a web project

c# - 使用动态 Linq 查询

c# - 为什么 AWS Lambda 环境中的 EPPlus Excel 库会抛出 "The type initializer for ' Gdip' 抛出异常”

.net - 正则表达式匹配除两个单词之外的任何内容