나는 다음과 같은 코드를 실행하려고하고있어 던졌습니다 :는 ManagementObjectSearcher 가져 오기() 메소드는 예외
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Processor");
// This line throws the exception
ManagementObjectCollection moc = mos.Get();
을하고 난 다음 excpetion 얻을 : 참고로
System.Management.ManagementException: Invalid class
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
at LicenseCheckThingy.Form1.button1_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
, 난 시스템을 실행중인 .net 3.5가 설치된 Windows XP SP 3 시스템입니다.
이 컴퓨터의 사용자는 관리자로 구성되어 있으며 howerver는 "Administrator"계정을 사용하지 않습니다.
오류의 증거로이 코드를 기초로 샘플 프로젝트를 만들었습니다. 나는 mos.Get() 줄이 오류 및 예외 텍스트를 던지는 줄인 간단한 표시 메시지를 추가하는 것으로부터 스택 추적의 "ManagementObjectEnumerator.MoveNext()"덕분에이를 지원하는 것으로 보입니다. 어쨌든, 나는 심지어 기계에서 무엇을 찾느냐에 관해서도 상실감을 느낍니다.
참고로이 50 개 이상의 다른 컴퓨터 (대다수의 Vista 또는 Windows 7)에서이 코드를 문제없이 실행 했으므로이 상자에만 해당되는 것처럼 보입니다. 내가 시도 할 수있는 것에 대한 제안/생각?
더 많은 정보 : 그래서 나는이 같은 예외가 발생하지만, 루프 선언
MessageBox.Show("pre setup"); // displays correctly
ManagementScope scope = new ManagementScope(@"\\" + Environment.MachineName + @"\root\cimv2");
//connect to the machine
scope.Connect();
MessageBox.Show("scope setup"); // displays correctly
//use a SelectQuery to tell what we're searching in
SelectQuery searchQuery = new SelectQuery("SELECT * FROM Win32_Processor");
//set the search up
ManagementObjectSearcher searcherObj = new ManagementObjectSearcher(scope, searchQuery);
MessageBox.Show("search object setup"); // displays correctly
//get the results into a collection
ManagementObjectCollection obj = searcherObj.Get();
MessageBox.Show("got ManagementObjectCollection"); // displays correctly
// next statement appears to cause Invalid class exception
foreach (ManagementObject mo in obj)
{
try
{
MessageBox.Show("looking for device id, cpu0"); // never shows up
if (string.Equals((string) mo["DeviceID"], "CPU0", StringComparison.InvariantCultureIgnoreCase))
{
MessageBox.Show("processor ID: " + mo["ProcessorID"].ToString()); // never shows up
break;
}
}
catch (Exception ex)
{
MessageBox.Show("Exception fetching processor id: " + ex.ToString()); // doesn't show
}
}
다른 도움을에, 시스템에 다음 코드를 실행했습니다 ??
이 하나 알아 낸 얻을 수 없습니다, Johnv2020 나를 프로세서 ID를 얻을 수 없습니다 윈도우 XP의 SP3의 버그 나 문제가있는 것이 좋습니다 웹 사이트를 생각했던 것 같다. 참고로, 프로세서는이 머신의 i5 650이며,이 경우 문제를 try catch에 랩핑하고이 경우 프로세서 ID를 무시함으로써이 문제를 "해결"했습니다. 도움을 준 Johnv2020에게 특별히 감사드립니다!
안녕을 어떻게 볼 시도 할 수 있습니다, 나를 위해 작동 확인 -이 링크를 체크 아웃하는 것처럼 보입니다 그 CPU 유형 및 SP3와의 문제 -에 http : // 뉴스 .softpedia.com/news/XP-SP3-Win32-Processor-Class-Labels-Intel-Core-2-Duo-CPUs-Incorectly-90201.shtml – Johnv2020
멋진 링크 !!! 나는 이것을 지금보고있다! – Beau
Beau, 사소한 요청으로, 내 대답을 유용하고 /거나 받아 들일 수 있다고 표시 할 수 있습니까? 다른 사람들에게 해결책이 있다는 것을 알려주는 것입니다. 감사합니다 – Johnv2020