2012-12-18 4 views
8

나는 이것을 달성하기 위해 지금까지 두 가지 방법을 시도했다.원격 컴퓨터에서 실행중인 프로세스에 대한 설명을 얻는 방법은 무엇입니까?

첫 번째 방법으로 System.Diagnostics을 사용했지만 MainModule에서 "기능이 원격 컴퓨터에서 지원되지 않습니다"라는 메시지가 NotSupportedException입니다.

foreach (Process runningProcess in Process.GetProcesses(server.Name)) 
{ 
    Console.WriteLine(runningProcess.MainModule.FileVersionInfo.FileDescription); 
} 

두 번째 방법

, 나는 System.Management를 사용하여 시도하지만 ManagementObjectDescriptionName과 동일한 그녀는 것 같다.

string scope = @"\\" + server.Name + @"\root\cimv2"; 
string query = "select * from Win32_Process"; 
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); 
ManagementObjectCollection collection = searcher.Get(); 

foreach (ManagementObject obj in collection) 
{ 
    Console.WriteLine(obj["Name"].ToString()); 
    Console.WriteLine(obj["Description"].ToString()); 
} 

원격 컴퓨터에서 실행중인 프로세스에 대한 설명을 얻는 더 좋은 방법에 대해 알고있는 사람이 있습니까?

+0

Rob van der Woude의 wmigen을 사용해 보셨나요? 사용할 수있는 것을 보여주는 데 도움이 될 수 있습니다. http://www.robvanderwoude.com/wmigen.php – Lizz

+0

@Lizz 글쎄, 이미 obj의 속성을 반복하면서 Property.ToString()이 설명에 포함되어 있어야하는 키워드를 포함했는지 확인했다. 내가 찾고있는 프로세스 중 하나 ... – athom

+0

Yikes. 죄송합니다. 다른 것을 생각할 수 없습니다. 좋은 코드와 문제 해결을 위해 +1 흥미 롭습니다. :) – Lizz

답변

4

글쎄, 내 생각에 충분히 잘 작동하는 방법이 있다고 생각한다. 기본적으로 ManagementObject에서 파일 경로를 가져 와서 실제 파일에서 설명을 가져 오는 중입니다.

ConnectionOptions connection = new ConnectionOptions(); 
connection.Username = "username"; 
connection.Password = "password"; 
connection.Authority = "ntlmdomain:DOMAIN"; 

ManagementScope scope = new ManagementScope(@"\\" + serverName + @"\root\cimv2", connection); 
scope.Connect(); 

ObjectQuery query = new ObjectQuery("select * from Win32_Process"); 
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); 
ManagementObjectCollection collection = searcher.Get(); 

foreach (ManagementObject obj in collection) 
{ 
    if (obj["ExecutablePath"] != null) 
    { 
     string processPath = obj["ExecutablePath"].ToString().Replace(":", "$"); 
     processPath = @"\\" + serverName + @"\" + processPath; 

     FileVersionInfo info = FileVersionInfo.GetVersionInfo(processPath); 
     string processDesc = info.FileDescription; 
    } 
} 
관련 문제