如何:擷取 Windows 版本 (C++/CLI)
下列程式碼範例會示範如何擷取目前作業系統的平台和版本資訊。 這項資訊儲存在 Environment.OSVersion 屬性中,由使用一般性的詞彙描述 Windows 版本的列舉型別 (Enumeration) 和包含精確的作業系統組建 (Build) 之 Version 物件所組成。
範例
// os_ver.cpp
// compile with: /clr
using namespace System;
int main()
{
OperatingSystem^ osv = Environment::OSVersion;
PlatformID id = osv->Platform;
Console::Write("Operating system: ");
if (id == PlatformID::Win32NT)
Console::WriteLine("Win32NT");
else if (id == PlatformID::Win32S)
Console::WriteLine("Win32S");
else if (id == PlatformID::Win32Windows)
Console::WriteLine("Win32Windows");
else
Console::WriteLine("WinCE");
Version^ version = osv->Version;
if (version)
{
int build = version->Build;
int major = version->Major;
int minor = version->Minor;
int revision = Environment::Version->Revision;
Console::Write("OS Version: ");
Console::WriteLine("{0}.{1}.{2}.{3}",
build, major, minor, revision);
}
return 0;
}