使用 ASP.NET 的 WMI 提供程序

发布于 2024-10-07 13:15:00 字数 1223 浏览 0 评论 0原文

我正在编写一个小型 ASP.NET 页面来检测和显​​示本地服务器上已安装 SSRS 实例的信息。

我发现 Microsoft 提供的以下工具非常有用... WMI Code Creator

它生成的代码在从命令行运行时效果很好。但是,当尝试在 ASP.NET 页面中执行相同的代码时,我收到...

“未处理的执行错误” 异常详细信息:System.Runtime.InteropServices.COMException

这是代码...

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\Microsoft\\SqlServer\\ReportServer\\[INSTANCE_HERE]\\v10\\Admin", "SELECT * FROM MSReportServer_ConfigurationSetting");

    foreach (ManagementObject queryObj in searcher.Get())
    {
        Response.Write(string.Format("InstanceName: {0}", queryObj["InstanceName"]));
    }

我的猜测是通过 IIS 存在某种权限问题,但是我将不胜感激您提供明确的答案。我认为这可能是所有通过 ASP.NET 的 WMI 提供程序的问题,但是以下代码在页面中工作正常...

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");

    foreach (ManagementObject queryObj in searcher.Get())
    {
        Response.Write(string.Format("Name: {0}", queryObj["Name"]));
    }

有关幕后到底发生了什么以及为什么我收到上述异常的任何帮助将非常受欢迎。

I'm writing a small ASP.NET page to detect and display information for installed SSRS instances on the local server.

I found the following tool really useful from Microsoft... WMI Code Creator

The code it generates works great when run from the command line. However when trying to execute the same code within my ASP.NET page I get a...

"Unhandled Execution Error"
Exception Details: System.Runtime.InteropServices.COMException

This is the code...

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\Microsoft\\SqlServer\\ReportServer\\[INSTANCE_HERE]\\v10\\Admin", "SELECT * FROM MSReportServer_ConfigurationSetting");

    foreach (ManagementObject queryObj in searcher.Get())
    {
        Response.Write(string.Format("InstanceName: {0}", queryObj["InstanceName"]));
    }

My guess is there is some sort of permissions issue via IIS, however I'd be grateful for a definitive answer. I thought it might be a problem with all WMI providers through ASP.NET, however the following code works fine in the page...

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");

    foreach (ManagementObject queryObj in searcher.Get())
    {
        Response.Write(string.Format("Name: {0}", queryObj["Name"]));
    }

Any help as to what exactly is going on behind the scenes and maybe why I'm getting the above exception would be very welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小伙你站住 2024-10-14 13:15:00

使用 dcomcnfg 将网络服务帐户添加到 DCOM 的启动条件中。

在cmd中输入dcomcnfg,

转到组件服务->我的电脑->Com安全->启动并激活权限->编辑默认值->添加...

现在添加网络服务并允许其所有权限。

add Network Service account into the launch conditions for DCOM using dcomcnfg.

Type dcomcnfg in cmd

go to Component Services ->My Computer ->Com Security ->Lauch and Activate Permissions ->Edit Default ->Add...

Now add Network Service and allow all permisions to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文