원격 컴퓨터에 아래 설정을 한다.
https://automationspecialist.wordpress.com/2011/10/10/troubleshoot-perfmon-exe-shows-error-message-unable-to-connect-to-machine/
프로그램에서 접근하는 계정이 혹은 원격 컴퓨터의 계정이
컴퓨터관리 / 그룹 / Performance Log Users 와 Performance Monitor Users 에 들어 있어야 한다.
혹은 Administrators 에 들어 있으면 된다. 음......
Remote Registry Service 를 enable 한다
해당 컴퓨터를 호스트에 등록한다.
C:\Windows\System32\drivers\etc
방화벽 열기
NetLogon 서비스 (NP-in) port no : 445
139번은 off 되어도 가능함
아래와 같이 Test 프로그램을 돌린다.
샘플 프로그램은 다음과 같다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Security.Principal;
using System.Threading;
using System.Runtime.InteropServices;
namespace CPUCounterTest
{
class Program
{
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
public const int LOGON32_LOGON_SERVICE = 3;
public const int LOGON32_PROVIDER_DEFAULT = 0;
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern bool LogonUser(
String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
static void Main(string[] args)
{
//AD01047147 al01023274
IntPtr userHandle = new IntPtr(0);
string username = "Naver";
string password = "";
string hostname = "al01023274";
// workGroup 환경이라도 아이디 암호가 같아야 한다.
LogonUser(username, hostname, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref userHandle);
WindowsIdentity identity = new WindowsIdentity(userHandle);
WindowsImpersonationContext context = identity.Impersonate();
PerformanceCounterCategory cat = new PerformanceCounterCategory("Processor", hostname);
List<PerformanceCounter> counters = new List<PerformanceCounter>();
foreach (string instance in cat.GetInstanceNames())
counters.Add(new PerformanceCounter("Processor", "% Processor Time", instance, hostname));
for (int i = 0; i < 10000; i++)
{
foreach (PerformanceCounter counter in counters)
Console.Write(counter.NextValue() +" ");
Console.WriteLine();
Thread.Sleep(800);
}
context.Undo();
}
}
}