2010-01-08 5 views
1

Windows와 Linux에서 모두 작동하는 .NET을 사용하여 컴퓨터를 고유하게 식별하는 방법이 필요합니다..NET/Mono를 사용하여 컴퓨터를 고유하게 식별합니까?

두 운영 체제에서 사용되는 방법이 동일 할 필요는 없습니다. 즉, Linux에서 Mono를 실행하는 방법과 Windows에서 .NET을 실행하는 또 다른 방법을 사용할 수 있습니다.

다른 컴퓨터에서 similar question을 보았습니다. NET에서 컴퓨터를 식별하는 기본 방법은 WMI를 사용하지만 OS가 무엇이든간에 Mono 컴퓨터에서 작동하는 것 같습니다.

제안 사항이 있습니다. 미리 감사드립니다.

답변

1

아니요, WMI는 Mono에서 작동하지 않습니다.

3

C#/Net 응용 프로그램 중 하나가 Linux에서 작동하는 중입니다 ... 그래서 리눅스와 Windows의 차이점을 해결할 방법을 찾아야합니다. .

이것은 매우, 매우 해키 롭습니다. 그리고 이것은 제가 당신을 위해 던진 대략적인 초안입니다. 이 그것을 할 수있는 더 좋은 방법은 아마,하지만 어쩌면 그것은 당신에게 아이디어를 줄 것이다 ...

bool IsRunningMono() 
{ 
    // With our application, it will be used on an embedded system, and we know that 
    // Windows will never be running Mono, so you may have to adjust accordingly. 
    return Type.GetType("Mono.Runtime") != null; 
} 

string GetCPUSerial() 
{ 
    string serial = ""; 

    if(IsRunningMono()) 
    { 
     ProcessStartInfo startInfo = new ProcessStartInfo(); 
     startInfo.FileName = "lshw"; 
     startInfo.Arguments = "-xml"; 
     startInfo.UseShellExecute = false; 
     startInfo.RedirectStandardOutput = true; 

     using(Process p = Process.Start(startInfo)) 
     { 
      p.WaitForExit(); 
      System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); 

      xdoc.Load(new System.Xml.XmlTextReader(new StringReader(p.StandardOutput.ReadToEnd()))); 

      System.Xml.XmlNodeList nodes = xdoc.SelectNodes("node/node/node/serial"); 

      if (nodes.Count > 0) 
      { 
       serial = nodes[0].InnerText;    
      } 
     }   
    } 
    else 
    { 
     // process using wmi 
    } 

    return serial; 
} 

내가 대신을 XmlDocument의 데이터 집합에로드 시도했지만 매번 실패했습니다. 우분투 9.10에서 테스트되었습니다. 희망이 당신을 올바른 방향으로 갈 수 있습니다.

+1

Type.GetType ("Mono.Runtime") 대신 http://msdn.microsoft.com/en-us/library/system.operatingsystem.platform.aspx를 확인하십시오. – skolima

관련 문제