中针对XP与Vista进行测试

中针对XP与Vista进行测试

本文介绍了如何在C#中针对XP与Vista进行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是有史以来最基本的问题,但我尚未找到答案.

This must be probably the most basic question ever, but I couldn't find an answer to it yet.


推荐答案

使用System.Runtime.InteropServices;
公共结构OSVERSIONINFOEX
{
公用uint dwOSVersionInfoSize;
公共public uint dwMajorVersion
public public uint dwMinorVersion;
public uint dwBuildNumber;
public public uint dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst 128 )]
公共字符串szCSDVersion;
public int16 wServicePackMajor;
public int16 wServicePackMinor;
public byte wProductType;
公用字节wReserved;
}
[DllImport("kernel32.dll", EntryPoint = &"; GetVersionEx" )]
公共静态外部UInt32 GetVersionEx(ref OSVERSIONINFOEXlpVersionInfo);
私有字符串GetOSVersion()
{
OSVERSIONINFOEX osviex == new OSVERSIONINFOEX();
osviex.dwOSVersionInfoSize ==(uint)元帅.SizeOf(osviex);
if(GetVersionEx(ref osviex)!= 0)
返回操作系统版本:" + osviex.dwMajorVersion +". + osviex.dwMinorVersion +". + osviex.dwBuildNumber;
否则
返回未能获得OS版本.";
}

using System.Runtime.InteropServices;  
 
public struct OSVERSIONINFOEX  
{  
    public uint dwOSVersionInfoSize;  
    public uint dwMajorVersion  
    public uint dwMinorVersion;  
    public uint dwBuildNumber;  
    public uint dwPlatformId;  
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]  
    public string szCSDVersion;  
    public Int16 wServicePackMajor;  
    public Int16 wServicePackMinor;  
    public Byte wProductType;  
    public Byte wReserved;  
}  
 
[DllImport("kernel32.dll", EntryPoint = "GetVersionEx")]  
public static extern UInt32 GetVersionEx(ref OSVERSIONINFOEX lpVersionInfo);  
 
private string GetOSVersion()  
{  
    OSVERSIONINFOEX osviex = new OSVERSIONINFOEX();  
    osviex.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osviex);      
 
    if (GetVersionEx(ref osviex) != 0)  
        return "OS Version: " + osviex.dwMajorVersion + "." + osviex.dwMinorVersion + "." + osviex.dwBuildNumber;  
      
    else      
        return "Failed to obtain OS version.";  


这篇关于如何在C#中针对XP与Vista进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:10