IIS + WMI:无法获取所有 WMI 信息
我正在尝试创建一个网络服务(WCF)来获取有关我的服务器的信息。我为 WMI 做了一个类,它可以检索有关 cpu、ram、磁盘等的信息...
在 Visual Studio 下,该服务工作正常,但是当我在 IIS 上部署该服务时,我得到了所有信息...除了一个!我有一个硬盘有两个分区(C 和 D),当我部署到 IIS 时,当我尝试检索第二个分区的“大小”时出现错误。该代码在控制台应用程序中运行良好。我也尝试过使用简单的 ASP.Net 网站而不是 WCF,也不起作用。
这是我使用的代码:
ConnectionOptions aCO { get; set; }
ManagementScope aMS { get; set; }
public Wmi()
{
aCO = new ConnectionOptions();
aMS = new ManagementScope("\\\\localhost", aCO);
}
.....
ObjectQuery aQ = new ObjectQuery("select Name,Size,FreeSpace from Win32_LogicalDisk where DriveType=3");
.....
foreach (ManagementObject oReturn in aRToSet)
{
string letter = oReturn["Name"].ToString();
long size = long.Parse(oReturn["Size"].ToString());
}
我做了一些测试,该服务在我的计算机(带有 IIS 7.5 的 Windows 7)上运行,但在我的服务器(Windows Server 2008)上运行不正常。
有人能给我任何线索吗?
谢谢。
I'm trying to make a webservice (WCF) to get information about my server. I made a class for WMI who can retreive information about cpu, ram, disks, etc...
Under visual studio, the service works fine, but when I deploy the service on IIS, I get all the information ... Except one ! I have one hard disk with two partition (C & D), when I deploy to IIS, there is an error when I try to retreive the "Size" of the second partition. The code works fine with a console application. I tried also with a simple ASP.Net website instead of WCF, doesn't work either.
Here is the code I use :
ConnectionOptions aCO { get; set; }
ManagementScope aMS { get; set; }
public Wmi()
{
aCO = new ConnectionOptions();
aMS = new ManagementScope("\\\\localhost", aCO);
}
.....
ObjectQuery aQ = new ObjectQuery("select Name,Size,FreeSpace from Win32_LogicalDisk where DriveType=3");
.....
foreach (ManagementObject oReturn in aRToSet)
{
string letter = oReturn["Name"].ToString();
long size = long.Parse(oReturn["Size"].ToString());
}
I made some tests, the service works on my computer (windows 7 with IIS 7.5) but not on my server (Windows Server 2008).
Could someone give me any clue ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现问题所在:
这是一个安全问题,唯一可以访问第二个磁盘(D:)的用户是超级管理员。我只是添加了管理员和用户组权限,现在我可以获取信息了!
I found what was wrong :
This was a security issue, the only user who can have access to the second disk (D:) was the super admin. I just add Administrator and User groups permissions, now I can get the infos !