【问题标题】:Using System.Management in my executable在我的可执行文件中使用 System.Management
【发布时间】:2015-09-25 16:37:42
【问题描述】:

C# 新手并拥有一个访问 Windows WMI 的控制台应用程序。我补充说:

using System.Management;
using System.Management.Instrumentation;

还添加了引用并将两个引用上的“CopyToLocal”设置为 true。我确实在“bin/debug”目录中看到了两个 .dll,但是,当在另一台计算机上运行时(我没有在其中编译源代码),我仍然收到两个引用未找到的错误。

有人可以帮忙吗?抱歉,我确信这是一个非常基本的问题。

我得到的例外是:

未处理的异常:System.UnauthorizedAccessException:访问 ID 被拒绝。 (来自 HRESULT 的异常: System.Runtime.InteropService.Marshal.ThrowExcetpionForHRInternal(Int32 errorcCode, IntPtr, errorInfo) 的 System.Runtime.InteropService.Marshal.ThrowExceptionForHR(Int32 errorCode) 的 System.Management.ManagementScope.InitializeGuts 的 0x80070005 (E_ACCESS_DENIED)对象 o) 在 System.Management.ManagementScrope.Initialize() 在 System.Management.ManagementScopt.Connect()

我真的很感谢所有的帮助!

【问题讨论】:

  • 您只是将 .exe 或整个调试文件夹复制到另一台计算机吗?
  • 您永远不会收到“找不到两个引用”的错误消息。不要将 Copy Local 设置为 true,请引用 exact 错误消息。
  • 我都尝试了 - 只是复制我的首选方法“.exe”和整个项目文件夹。实际错误是:未处理的异常:System.UnauthorizedAccessException:访问 id 被拒绝。 (来自 HRESULT 的异常: System.Runtime.InteropService.Marshal.ThrowExcetpionForHRInternal(Int32 errorcCode, IntPtr, errorInfo) 的 System.Runtime.InteropService.Marshal.ThrowExceptionForHR(Int32 errorCode) 的 System.Management.ManagementScope.InitializeGuts 的 0x80070005 (E_ACCESS_DENIED)对象 o) 在 System.Management.ManagementScrope.Initialize() 在 System.Management.ManagementScopt.Connect()
  • 我已将异常消息复制到问题中,以方便他人查看。

标签: c# reference wmi


【解决方案1】:

请参阅以下 YouTube 剪辑 - 像魅力一样工作(C# 如何嵌入和引用外部程序集 (DLL) - Windows 窗体)https://www.youtube.com/watch?v=x-KK7bmo1AM

【讨论】:

    猜你喜欢
    • 2021-02-14
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多