无法在 ASP.Net Web 应用程序中获取 IIS WMI 信息
操作系统:Windows 2008 R2 Web Server Edition
问题:无法通过 ASP.net 4.0 Web 应用程序中的 Win32_PerfRawData_W3SVC_WebService
类获取本地服务器的 IIS 信息
背景:
我可以在
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 接下来
我尝试在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:
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
NextI 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论