1
我试图通过填充ManagementScope变量并尝试连接到远程计算机来通过服务连接到Windows WMI。如果我作为Windows控制台运行,则连接成功,但在从Windows服务运行相同代码时失败。ManagementScope.Connect失败,并从Windows服务运行时出错E_ACCESSDENIED错误
代码荫使用如下:
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服务作为本地系统。代码是用C#编写的.net 4.0版本
任何帮助非常感谢。
感谢