Click here to Skip to main content
15,889,691 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am working on a website that in part, connects to remote computers to obtain various performance counter data.

The problem is that I'm getting access denied errors. I've read that to access perfmon counters, you need administrative rights on that machine.

In my Visual Studio 2008/VB web application, how do I provide the credentials so that the remote perfmon variables can be accessed?

Here is my code. Note that the first Try/Catch block has a line with ".machinename = hostname". This is where I specify the remote computer. The Access Denied error occurs on the msgbox lines at the bottom of the procedure.

VB
Protected Sub GetPerfMonMetrics(ByVal Hostname As String)
        'This process will connect to a remote host and read/collect the relevant PerfMon Data.
        'Disk utilization for all local drives.
        'Overall CPU Utilization
        'Memory usage for each messagse broker
        'Values for the threadq's.

        '       MsgBox("Executing Sub-routine GetPerfMonMetrics for " & Hostname)
        Dim perf_processor As New PerformanceCounter("Processor", "% Processor Time")
        Dim perf_logdisk As New PerformanceCounter("LogicalDisk", "% Free Space")
        Dim perf_process As New PerformanceCounter("Process", "Working Set", "MSAccess")

        Try
            With perf_processor
                .MachineName = Hostname
                .CategoryName = "Processor"
                .CounterName = "% Processor Time"
                .InstanceName = "_Total"
            End With
        Catch
            MsgBox("Error reading the % Processor Time counter.")
        End Try

        Try
            With perf_logdisk
                .CategoryName = "LogicalDisk"
                .CounterName = "% Free Space"
                .InstanceName = "C:"
            End With
        Catch
            MsgBox("Error reading the Logical Disk, %Free Space counter.")
        End Try

        Try
            With perf_process
                .CategoryName = "Process"
                .CounterName = "Working Set"
            End With
        Catch
            MsgBox("Error reading the % Process Working Set counter.")
        End Try

        System.Threading.Thread.Sleep(1000)
        MsgBox("CPU usage = " & perf_processor.NextValue())
        MsgBox("Access memory used/working set = " & perf_process.NextValue())
        MsgBox("Logical Disk " & perf_logdisk.NextValue())

    End Sub
Posted
Updated 30-Oct-14 22:55pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900