Hier ist ein Beispiel mit GetProductInfo aus kernel32.dll.
using System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("kernel32.dll")]
static extern bool GetProductInfo(int dwOSMajorVersion, int dwOSMinorVersion, int dwSpMajorVersion, int dwSpMinorVersion, out int pdwReturnedProductType);
static void Main()
{
int productType;
GetProductInfo(Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, 0, 0, out productType);
if (IsServer(productType))
{
Console.WriteLine("Das System ist ein Windows Server.");
}
else
{
Console.WriteLine("Das System ist ein Windows Client.");
}
}
static bool IsServer(int productType)
{
// Liste der möglichen Server-Typen
return productType == 0x0000000A || // Server Standard Edition
productType == 0x0000000C || // Server Datacenter Edition
productType == 0x0000000D || // Server Enterprise Edition
productType == 0x00000027 || // Server Essentials Edition
productType == 0x00000037; // Server Datacenter Nano Edition
}
}