Is there any another property to retrieve the operating system in C# other than Environment.OsVersion because this property is not determining in case of Mac OS?
You can do something like this(according to Mono Wiki)
string msg1 = "This is a Windows operating system.";
string msg2 = "This is a Unix operating system.";
string msg3 = "This is a OSX operating system.";
string msg4 = "ERROR: This platform identifier is invalid.";
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
switch (pid)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
Console.WriteLine(msg1);
break;
case PlatformID.Unix:
Console.WriteLine(msg2);
break;
case PlatformID.MacOSX:
Console.WriteLine(msg3);
break;
default:
Console.WriteLine(msg4);
break;
}
If you are using asp.net you can use javascript for detecting the OS
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
document.write('Your OS: '+OSName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With