Hi! I have this method that gets the OS suite and product type, but it
is always returning null. Can anyone help me, please? Here is the method
and other necessary code:
[StructLayout(La youtKind.Sequen tial)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfo Size;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 128)]
public string szCSDVersion;
public int wServicePackMaj or;
public int wServicePackMin or;
public int wSuiteMask;
public byte wProductType;
public byte wReserved;
}
[DllImport("kern el32.dll", EntryPoint="Get VersionEx")]
private static extern bool GetVersionEx(re f OSVERSIONINFOEX
osVersionInfo);
#region Private Constants
private const Int32 VER_NT_WORKSTAT ION = 1;
private const Int32 VER_NT_DOMAIN_C ONTROLLER = 2;
private const Int32 VER_NT_SERVER = 3;
private const Int32 VER_SUITE_SMALL BUSINESS = 1;
private const Int32 VER_SUITE_ENTER PRISE = 2;
private const Int32 VER_SUITE_TERMI NAL = 16;
private const Int32 VER_SUITE_DATAC ENTER = 128;
private const Int32 VER_SUITE_SINGL EUSERTS = 256;
private const Int32 VER_SUITE_PERSO NAL = 512;
private const Int32 VER_SUITE_BLADE = 1024;
#endregion
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string OSProductType()
{
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX ();
OperatingSystem osInfo = Environment.OSV ersion;
osVersionInfo.d wOSVersionInfoS ize = Marshal.SizeOf( osVersionInfo);
if(!GetVersionE x(ref osVersionInfo))
{
return "";
}
else
{
if(osInfo.Versi on.Major == 4)
{
if(osVersionInf o.wProductType == VER_NT_WORKSTAT ION)
{
// Windows NT 4.0 Workstation
return " Workstation";
}
else if(osVersionInf o.wProductType == VER_NT_SERVER)
{
// Windows NT 4.0 Server
return " Server";
}
else
{
return "";
}
}
else if(osInfo.Versi on.Major == 5)
{
if(osVersionInf o.wProductType == VER_NT_WORKSTAT ION)
{
if((osVersionIn fo.wSuiteMask & VER_SUITE_PERSO NAL) ==
VER_SUITE_PERSO NAL)
{
// Windows XP Home Edition
return " Home Edition";
}
else
{
// Windows XP / Windows 2000 Professional
return " Professional";
}
}
else if(osVersionInf o.wProductType == VER_NT_SERVER)
{
if(osInfo.Versi on.Minor == 0)
{
if((osVersionIn fo.wSuiteMask & VER_SUITE_DATAC ENTER) ==
VER_SUITE_DATAC ENTER)
{
// Windows 2000 Datacenter Server
return " Datacenter Server";
}
else if((osVersionIn fo.wSuiteMask & VER_SUITE_ENTER PRISE) ==
VER_SUITE_ENTER PRISE)
{
// Windows 2000 Advanced Server
return " Advanced Server";
}
else
{
// Windows 2000 Server
return " Server";
}
}
else
{
if((osVersionIn fo.wSuiteMask & VER_SUITE_DATAC ENTER) ==
VER_SUITE_DATAC ENTER)
{
// Windows Server 2003 Datacenter Edition
return " Datacenter Edition";
}
else if((osVersionIn fo.wSuiteMask & VER_SUITE_ENTER PRISE) ==
VER_SUITE_ENTER PRISE)
{
// Windows Server 2003 Enterprise Edition
return " Enterprise Edition";
}
else if((osVersionIn fo.wSuiteMask & VER_SUITE_BLADE ) ==
VER_SUITE_BLADE )
{
// Windows Server 2003 Web Edition
return " Web Edition";
}
else
{
// Windows Server 2003 Standard Edition
return " Standard Edition";
}
}
}
}
}
return "";
}
is always returning null. Can anyone help me, please? Here is the method
and other necessary code:
[StructLayout(La youtKind.Sequen tial)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfo Size;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 128)]
public string szCSDVersion;
public int wServicePackMaj or;
public int wServicePackMin or;
public int wSuiteMask;
public byte wProductType;
public byte wReserved;
}
[DllImport("kern el32.dll", EntryPoint="Get VersionEx")]
private static extern bool GetVersionEx(re f OSVERSIONINFOEX
osVersionInfo);
#region Private Constants
private const Int32 VER_NT_WORKSTAT ION = 1;
private const Int32 VER_NT_DOMAIN_C ONTROLLER = 2;
private const Int32 VER_NT_SERVER = 3;
private const Int32 VER_SUITE_SMALL BUSINESS = 1;
private const Int32 VER_SUITE_ENTER PRISE = 2;
private const Int32 VER_SUITE_TERMI NAL = 16;
private const Int32 VER_SUITE_DATAC ENTER = 128;
private const Int32 VER_SUITE_SINGL EUSERTS = 256;
private const Int32 VER_SUITE_PERSO NAL = 512;
private const Int32 VER_SUITE_BLADE = 1024;
#endregion
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string OSProductType()
{
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX ();
OperatingSystem osInfo = Environment.OSV ersion;
osVersionInfo.d wOSVersionInfoS ize = Marshal.SizeOf( osVersionInfo);
if(!GetVersionE x(ref osVersionInfo))
{
return "";
}
else
{
if(osInfo.Versi on.Major == 4)
{
if(osVersionInf o.wProductType == VER_NT_WORKSTAT ION)
{
// Windows NT 4.0 Workstation
return " Workstation";
}
else if(osVersionInf o.wProductType == VER_NT_SERVER)
{
// Windows NT 4.0 Server
return " Server";
}
else
{
return "";
}
}
else if(osInfo.Versi on.Major == 5)
{
if(osVersionInf o.wProductType == VER_NT_WORKSTAT ION)
{
if((osVersionIn fo.wSuiteMask & VER_SUITE_PERSO NAL) ==
VER_SUITE_PERSO NAL)
{
// Windows XP Home Edition
return " Home Edition";
}
else
{
// Windows XP / Windows 2000 Professional
return " Professional";
}
}
else if(osVersionInf o.wProductType == VER_NT_SERVER)
{
if(osInfo.Versi on.Minor == 0)
{
if((osVersionIn fo.wSuiteMask & VER_SUITE_DATAC ENTER) ==
VER_SUITE_DATAC ENTER)
{
// Windows 2000 Datacenter Server
return " Datacenter Server";
}
else if((osVersionIn fo.wSuiteMask & VER_SUITE_ENTER PRISE) ==
VER_SUITE_ENTER PRISE)
{
// Windows 2000 Advanced Server
return " Advanced Server";
}
else
{
// Windows 2000 Server
return " Server";
}
}
else
{
if((osVersionIn fo.wSuiteMask & VER_SUITE_DATAC ENTER) ==
VER_SUITE_DATAC ENTER)
{
// Windows Server 2003 Datacenter Edition
return " Datacenter Edition";
}
else if((osVersionIn fo.wSuiteMask & VER_SUITE_ENTER PRISE) ==
VER_SUITE_ENTER PRISE)
{
// Windows Server 2003 Enterprise Edition
return " Enterprise Edition";
}
else if((osVersionIn fo.wSuiteMask & VER_SUITE_BLADE ) ==
VER_SUITE_BLADE )
{
// Windows Server 2003 Web Edition
return " Web Edition";
}
else
{
// Windows Server 2003 Standard Edition
return " Standard Edition";
}
}
}
}
}
return "";
}
Comment