I would like to determine if my program is running on a version of Windows Server. Apparently, System.Environment
does not contain information about the fact th
I had the same issue, albeit in scripting.
I have found this value; I am querying it using WMI:
https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
Win32_OperatingSystem
ProductType
Data type: uint32
Access type: Read-only
Additional system information.
Work Station (1)
Domain Controller (2)
Server (3)
I tested this for the following operating system versions:
Find my example batch file below.
Lucas.
for /f "tokens=2 delims==" %%a in ( 'wmic.exe os get producttype /value' ) do (
set PRODUCT_TYPE=%%a
)
if %PRODUCT_TYPE%==1 set PRODUCT_TYPE=Workstation
if %PRODUCT_TYPE%==2 set PRODUCT_TYPE=DomainController
if %PRODUCT_TYPE%==3 set PRODUCT_TYPE=Server
echo %COMPUTERNAME%: %PRODUCT_TYPE%
You can easily do this in C#:
using Microsoft.Management.Infrastructure;
...
string Namespace = @"root\cimv2";
string className = "Win32_OperatingSystem";
CimInstance operatingSystem = new CimInstance(className, Namespace);