Access denied reading Perfmon counters from a remote machine (Asp.Net)

I am trying to create a simple Asp.Net page to read Perfmon counters from a remote machine.

When I launch the page using the Visual Studio development web server, everything is fine, however, when I try to launch the same page when it is hosted in IIS, I get a denied access error on the line that creates the Perfmon instance:

PerformanceCounter freeSpaceCounter = new PerformanceCounter("LogicalDisk", "Free Megabytes", "D:", "RemoteMachine12");

This is the exception I get:

Exception Details: System.ComponentModel.Win32Exception: Access is denied

I tried using anonymous access (with myself as an anonymous user) and integrated Windows authentication - both do not work. Obviously, some other accounts are used to read PerfMon counters (for example, for an ASPNET account). How to get my page to access PerfMon counters using my account, and not this account?

+5
source share
2 answers

, , , IIS ( ). . - VS, .

, IIS , , .

, ( IIS7 , ) .

- IIS ,

PerformanceCounter freeSpaceCounter = null;
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
    freeSpaceCounter = new PerformanceCounter("LogicalDisk", 
                               "Free Megabytes", "D:", "RemoteMachine12");
}

, - , . KB306158

+6

MSDN:

Windows Vista, Windows XP Professional x64 Edition Windows Server 2003, , .

+2

All Articles