远程连接WMI ,HRESULT:0x80070005 (E_ACCESSDENIED))

Environment:  local -1703/remote-1709: Win10 Pro 64bit 

Preparasion:

1. local/remote都启动WS-Man服务即WinRM .  local启动winrm -quickstart. 添加所有机器(即*)到trustedhosts里. remote端只quickstart

     Ref: http://labs.supinfochina.com/en/powershell-configure-winrm-and-enable-psremoting/#_Toc429317714

2. 保证local/remote的WMI service在运行

3. 保证local访问root\cimv2没问题(用wbemtest.exe)

4. 关闭remote防火墙(所有)

问题:

1. 本来想玩转WMI的一个自带工具,C:\windows\system32\wbem\Wbemtest.exe ,结果这个工具connect同网络同workgroup的另一台机器被拒绝(我用的remote的admin用户),得到错误0x80070005!!

2. 想到MI已经取代WMI, WS-Man应该也可以,remote端Powershell启用Enable-PSRemoting。local的Powershell使用Get-WSManInstance -ResourceURI wmicimv2/win32_service -SelectorSet @{name="winrm"} -ComputerName "Server01" -credential admin (我用的remote的admin用户), 结果还是错误<f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="5" Machine="xxx"><f:Message>拒绝访问。 </f:Message>

3. 用C#代码通过WS-Man协议IEnumerable<CimInstance> enumeratedInstances = cimSession.EnumerateInstances(cimNamespace, cimClassName);

    也会得到同样错误

解决方法
      方案A:  Remote端的注册表里添加特定valuename/value.
       KEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/ 下添加 LocalAccountTokenFilterPolicy,类型REG_WORD,值1. 然后尝试之前2种方法,都成功!!

    Ref: https://blog.techygeekshome.info/2014/02/remote-uac-access-denied-errors-local-account-token-filter-policy-remote-uac-fix/

     优点:方便,快. 无论wbemtest.exe/powershell/C#使用都畅通无阻。

      缺点:这种方法其实是disable了remote UAC !!!对于学习或偷懒来说方便,用管理员账户登录就完全是管理员权限了,但是安全性就下降许多。


原因: "WMI tasks remotely accessing WMI information on this computer and requiring Administrative privileges MUST use a DOMAIN account part of the Local Administrators group of this computer to ensure that administrative privileges are granted. If a Local User account is used for remote accesses, it will be reduced to a plain user (filtered token), even if it is part of the Local Administrators group."
   Ref : https://serverfault.com/questions/713643/windows-10-wmi-and-event-viewer-access-denied

    MSDN描述---In a workgroup, the account connecting to the remote computer is a local user on that computer. Even if the account is in the Administrators group, UAC filtering means that a script runs as a standard user

            即使你用的remote端具有管理员权限的账户链接,UAC会把它降级为标准用户,所以本地端绝大多数访问都会被拒绝

   Ref: https://msdn.microsoft.com/en-us/library/aa826699(v=vs.85).aspx#handling_remote_connections_under_uac

方案B: 根据MSDN描述,创建只用于remote的用户与用户组,再在WMI Control(Computer Management)里,指定该用户(组)能访问哪些Namespace。比如我就创建了一个onlyRemote用户,只属于Remote Management Users但不属于administrators。

优点:安全!!

缺点:要花时间配置好Namespace范围。很多security object会要求administrator权限,在Powershell里或C#用我的onlyRemote(同时也在Administrators组里)访问Win32_Service就会出现Access Denied了,访问Win32_process不会。而我的wbemtest.exe用onlyRemote用户连接remote被完全拒绝.           

Ref: https://social.technet.microsoft.com/Forums/lync/en-US/4f33837b-1cb1-4648-85b1-3ba87cbfe93e/wmi-remote-access-denied?forum=winserverManagement

     DCOM应该是限制老式WMI的,如果不用Ws-Man访问,就还要在DCOM里指定remote权限. 通过dcomcnfg.exe修改DCOM security

PS: 在诊断Access Denied问题还用到了WMIDiag,可以辅助判断WMI潜在的问题,这次这个问题就是通过它提示发现的。


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常与 WMI(Windows Management Instrumentation)服务相关,可能是 WMI 子系统或命名空间出现了问题。以下是一些可能的解决方法: 1. 重新启动 WMI 服务 在 Windows 搜索栏中输入“services.msc”,找到“Windows Management Instrumentation”服务,右键单击并选择“重启”。 2. 重置 WMI 服务 打开命令提示符(以管理员身份运行),输入以下命令并按回车键: ``` winmgmt /resetrepository ``` 这将重置 WMI 子系统的状态并重新构建 WMI 数据存储库。 3. 修复 WMI 子系统 打开命令提示符(以管理员身份运行),输入以下命令并按回车键: ``` winmgmt /salvagerepository %windir%\System32\wbem ``` 这将尝试修复损坏的 WMI 子系统文件,并将它们移动到重建存储库所需的位置。 4. 重新注册 WMI DLL 文件 打开命令提示符(以管理员身份运行),输入以下命令并按回车键: ``` regsvr32 wbemcons.dll regsvr32 wbemcore.dll regsvr32 wbemess.dll regsvr32 wbemsvc.dll regsvr32 fastprox.dll regsvr32 winmgmts.exe ``` 这将重新注册 WMI DLL 文件,可能会解决问题。 5. 运行系统文件检查器 打开命令提示符(以管理员身份运行),输入以下命令并按回车键: ``` sfc /scannow ``` 这将运行系统文件检查器,并尝试修复任何受损的系统文件。 如果上述解决方法都无法解决问题,可能需要重新安装操作系统或寻求专业技术支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值