在 Environment.OSVersion.ServicePack 我只看到 ServicePack 变量,但没有主要或次要版本,我如何获得主要或次要版本?
问问题
1048 次
2 回答
2
您可以使用以下代码。
void Main()
{
GetServicePackVersion().Major.Dump();
}
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
public short wServicePackMajor;
public short wServicePackMinor;
public short wSuiteMask;
public byte wProductType;
public byte wReserved;
}
[DllImport("kernel32.dll")]
private static extern bool GetVersionEx([In, Out] ref OSVERSIONINFOEX osVersionInfo);
public static Version GetServicePackVersion()
{
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo))
{
Version result = new Version(osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor);
return result;
}
else
{
return null;
}
}
于 2014-07-25T17:23:09.530 回答
-1
Service Pack 没有主要或次要版本。您必须探索Environment.OSVersion.Version
以获取必要的版本信息。
于 2013-07-19T18:10:08.607 回答