admin管理员组文章数量:1200397
I am creating an ASP.NET MVC web app to query a list of server resources like Disk Space, RAM and CPU using WMI classes. Everything worked as expected from my local development environment. All the queries are called using a user account with Admin privileges to all those servers.
When I hosted the web app on an IIS server, all of the queries failed for the server where the web app is hosted. The failure message was
User credentials cannot be used for local connections
The answer I obtained from searching the web is that you shouldn't pass the user account when you are query resources on the server that you hosted your app so I made the change and almost all queries worked except 2 with a new error
Object reference not set to an instance of an object
The errors are pointed to the line of codes below. I am not sure why this error so I create this post to ask for help with issue.
The 2 queries that caused errors are:
ConnectionOptions options = new ConnectionOptions();
option.UserName = <username_goes here>
option.Password = <password_goes_here>
ManagementScope scope = new ManagementScope(strNameSpace, options)
ObjectQuery query = new ObjectQuery("select AvailableBytes FROM Win32_PerfFormattedData_PerfOS_Memory");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
and
ObjectQuery query2 = new ObjectQuery("select AvailableBytes FROM Win32_PerfFormattedData_PerfOS_Memory");
本文标签: cGetting AvailableBytes of memory and PercentIdleTime of CPU from a remote serversStack Overflow
版权声明:本文标题:c# - Getting AvailableBytes of memory and PercentIdleTime of CPU from a remote servers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738599759a2101997.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论