【问题标题】:ManagementScope.Connect failing with error E_ACCESSDENIED error while being run from Windows Service从 Windows 服务运行时,ManagementScope.Connect 失败并出现错误 E_ACCESSDENIED 错误
【发布时间】:2011-09-26 00:36:16
【问题描述】:

我正在尝试通过填充 ManagementScope 变量并尝试连接到远程计算机来通过服务连接到 Windows WMI。如果我作为 Windows 控制台运行,则连接成功,但当我从 Windows 服务运行相同的代码时连接失败。

我使用的代码如下:

ManagementScope scope = null;

scope = new ManagementScope("\\\\" + m_sComputerName + "\\root\\cimv2");
if (m_sLoginName != null && m_sPassword != null)
{
    scope.Options.Username = m_sLoginName;
    scope.Options.Password = m_sPassword;
}

scope.Options.EnablePrivileges = true;
scope.Options.Authentication = AuthenticationLevel.PacketPrivacy;
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Connect();

我将 Windows 服务作为本地系统运行。代码是用 .net 4.0 版的 C# 编写的

非常感谢任何帮助。

谢谢

【问题讨论】:

    标签: c# wmi


    【解决方案1】:

    默认情况下,LocalSystem 帐户无权访问网络资源 - 请参阅 here。如果您需要从您的服务访问网络资源,请考虑将其作为域帐户运行。虽然可以授权对 LocalSystem 的远程资源的访问,但不建议这样做。另一种选择是将服务作为 NT AUTHORITY\NetworkService 运行 - 请参阅here,在这种情况下,服务将在访问网络资源时作为机器帐户进行身份验证。

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多