在vs2005新建一个clr项目,选择控制台程序。
using namespace System;
using namespace System::Management;
using namespace System::Windows::Forms;
int main(array<System::String ^> ^args)
{
String^ str;
ManagementClass^ mClass = gcnew ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection^ moCollection;
ManagementObject^ mObject=gcnew ManagementObject();
moCollection = mClass->GetInstances();
for each (mObject in moCollection)
{
str += mObject["SerialNumber"]->ToString();
}
System::Console::WriteLine(str);
MessageBox::Show(str);
return 0;
}