操作系统:Windows 2008 R2 Web服务器版
问题:无法通过ASP.net 4.0 Web应用程序中的Win32_PerfRawData_W3SVC_WebService
类获取本地服务器的IIS信息
背景:
我可以在服务器上的VBS脚本中获取信息Win32_PerfRawData_W3SVC_WebService
。
strComputer =“。” 设置objWMIService = GetObject(“winmgmts:\”& strComputer&“\ root \ CIMV2”) 设置colItems = objWMIService.ExecQuery(_ “SELECT * FROM Win32_PerfRawData_W3SVC_WebService WHERE Name ='Cms2012'”,, 48) 对于colItems中的每个objItem Wscript.Echo“CurrentConnections:”& objItem.CurrentConnections 下一步
我尝试在 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;
}
}
}