无法在 ASP.Net Web 应用程序中获取 IIS WMI 信息

发布于 2024-12-23 01:11:29 字数 1958 浏览 0 评论 0原文

操作系统:Windows 2008 R2 Web Server Edition

问题:无法通过 ASP.net 4.0 Web 应用程序中的 Win32_PerfRawData_W3SVC_WebService 类获取本地服务器的 IIS 信息

背景

  1. 我可以在Win32_PerfRawData_W3SVC_WebService中获取信息服务器上的VBS脚本。

    strComputer =“。” 设置 objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2") 设置 colItems = objWMIService.ExecQuery( _ “从 Win32_PerfRawData_W3SVC_WebService 中选择 *,其中名称='Cms2012'”,,48) 对于 colItems 中的每个 objItem Wscript.Echo "CurrentConnections: " & objItem.CurrentConnections 接下来

  2. 我尝试在wmimgmt.msc中授予权限。同时启用 IIS_IUSRS 和 IUSR,但没有帮助

请有人帮助我为什么我无法从以下代码中获取信息?它在我的测试机上成功了。

 ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_PerfRawData_W3SVC_WebService WHERE Name='Cms2012' ");
 using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, query))
 {
     using (ManagementObjectCollection coll = managementObjectSearcher.Get())
     {
         foreach (ManagementObject obj in coll)
         {
             iisStatus.Add( string.Format("Current connections: {0}", obj["CurrentConnections"]) );
             iisStatus.Add( string.Format("Current anonymous users: {0}", obj["CurrentAnonymousUsers"]));
             iisStatus.Add( string.Format("Current non anonymous users: {0}", obj["CurrentNonAnonymousUsers"]));
             iisStatus.Add( string.Format("Maximum connections: {0}", obj["MaximumConnections"]));
             iisStatus.Add( string.Format("Service up time: {0} seconds", obj["ServiceUptime"]));
             iisStatus.Add( string.Format("Bytes received: {0:N2}MB", (ulong)obj["TotalBytesReceived"] / 1024.00M / 1024.00M));
             iisStatus.Add(string.Format("Bytes sent: {0:N2}MB", (ulong)obj["TotalBytesSent"] / 1024.00M / 1024.00M));
             break;
         }
     }
 }

Operation System: Windows 2008 R2 Web Server Edition

Problem: Can not get IIS information of local server via Win32_PerfRawData_W3SVC_WebService class in ASP.net 4.0 Web Application

Background:

  1. I can get information Win32_PerfRawData_W3SVC_WebService in VBS script on the server.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_PerfRawData_W3SVC_WebService WHERE Name='Cms2012'",,48)
    For Each objItem in colItems
    Wscript.Echo "CurrentConnections: " & objItem.CurrentConnections
    Next

  2. I tried to granted the permission in wmimgmt.msc. Enable both IIS_IUSRS and IUSR, but it does not help

Please can someone help me why I can't get the information from following code? it succeed in my test machine.

 ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_PerfRawData_W3SVC_WebService WHERE Name='Cms2012' ");
 using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, query))
 {
     using (ManagementObjectCollection coll = managementObjectSearcher.Get())
     {
         foreach (ManagementObject obj in coll)
         {
             iisStatus.Add( string.Format("Current connections: {0}", obj["CurrentConnections"]) );
             iisStatus.Add( string.Format("Current anonymous users: {0}", obj["CurrentAnonymousUsers"]));
             iisStatus.Add( string.Format("Current non anonymous users: {0}", obj["CurrentNonAnonymousUsers"]));
             iisStatus.Add( string.Format("Maximum connections: {0}", obj["MaximumConnections"]));
             iisStatus.Add( string.Format("Service up time: {0} seconds", obj["ServiceUptime"]));
             iisStatus.Add( string.Format("Bytes received: {0:N2}MB", (ulong)obj["TotalBytesReceived"] / 1024.00M / 1024.00M));
             iisStatus.Add(string.Format("Bytes sent: {0:N2}MB", (ulong)obj["TotalBytesSent"] / 1024.00M / 1024.00M));
             break;
         }
     }
 }

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文