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에서 테스트되었습니다. 희망이 당신을 올바른 방향으로 갈 수 있습니다.
Type.GetType ("Mono.Runtime") 대신 http://msdn.microsoft.com/en-us/library/system.operatingsystem.platform.aspx를 확인하십시오. – skolima