Exemplo n.º 1
0
            static bool IsWindowsServer()
            {
                try
                {
                    const int OS_ANYSERVER = 29;
                    return(IsOS(OS_ANYSERVER));
                }
                catch
                {
                    // isn't supported in nano server
                }

                try
                {
                    const uint VER_PRODUCT_TYPE   = 0x0000080;
                    const byte VER_EQUAL          = 1;
                    const byte VER_NT_WORKSTATION = 0x0000001;

                    var osvi = new OSVERSIONINFOEXW
                    {
                        dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEXW)),
                        wProductType        = VER_NT_WORKSTATION
                    };

                    var dwlConditionMask = VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL);

                    var result = VerifyVersionInfoW(ref osvi, VER_PRODUCT_TYPE, dwlConditionMask) == false;
                    return(result);
                }
                catch
                {
                    // failed to identify if running in Windows Server. assuming that we aren't.
                    return(false);
                }
            }
Exemplo n.º 2
0
        public static bool RtlGetVersion(ref OSVERSIONINFOEXW lpVersionInformation)
        {
            IntPtr proc = GetProcAddress(GetNtDll(), "RtlGetVersion");

            NativeSysCall.Delegates.RtlGetVersion RtlGetVersion = (NativeSysCall.Delegates.RtlGetVersion)Marshal.GetDelegateForFunctionPointer(proc, typeof(NativeSysCall.Delegates.RtlGetVersion));
            return(RtlGetVersion(ref lpVersionInformation));
        }
Exemplo n.º 3
0
        static Version GetRtlVersion()
        {
            OSVERSIONINFOEXW info = new OSVERSIONINFOEXW();

            info.dwOSVersionInfoSize = Marshal.SizeOf(info);

            RtlGetVersion(ref info);

            return(new Version(info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber));
        }
Exemplo n.º 4
0
        IsWindowsServer()
        {
            var osvi = new OSVERSIONINFOEXW
            {
                dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEXW)),
                wProductType        = VER_NT_WORKSTATION
            };

            var dwlConditionMask = VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL);

            return(!VerifyVersionInfoW(ref osvi, VER_PRODUCT_TYPE, dwlConditionMask));
        }
Exemplo n.º 5
0
        public static bool IsWindowsVersionOrGreater(int majorVersion, int minorVersion, short servicePackMajor)
        {
            var osvi = new OSVERSIONINFOEXW();

            osvi.dwOSVersionInfoSize = Marshal.SizeOf <OSVERSIONINFOEXW>();
            var mask = VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL), VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

            osvi.dwMajorVersion    = majorVersion;
            osvi.dwMinorVersion    = minorVersion;
            osvi.wServicePackMajor = servicePackMajor;
            return(VerifyVersionInfoW(ref osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, mask));
        }
Exemplo n.º 6
0
        IsWindowsVersionOrGreater(ushort wMajorVersion, ushort wMinorVersion, ushort wServicePackMajor)
        {
            var osvi = new OSVERSIONINFOEXW
            {
                dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEXW))
            };

            var dwlConditionMask = VerSetConditionMask(
                VerSetConditionMask(
                    VerSetConditionMask(
                        0, VER_MAJORVERSION, VER_GREATER_EQUAL),
                    VER_MINORVERSION, VER_GREATER_EQUAL),
                VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

            osvi.dwMajorVersion    = wMajorVersion;
            osvi.dwMinorVersion    = wMinorVersion;
            osvi.wServicePackMajor = wServicePackMajor;

            return(VerifyVersionInfoW(ref osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE);
        }
Exemplo n.º 7
0
        static bool IsWindowsVersionOrGreater(ushort wMajorVersion, ushort wMinorVersion, ushort wBuildVersion /* wServicePackMajor */)
        {
            OSVERSIONINFOEXW osvi = new OSVERSIONINFOEXW();

            osvi.dwOSVersionInfoSize = Marshal.SizeOf(osvi);

            int buildNumberMask = VER_BUILDNUMBER; /* VER_SERVICEPACKMAJOR */

            ulong dwlConditionMask = VerSetConditionMask(
                VerSetConditionMask(
                    VerSetConditionMask(
                        0, VER_MAJORVERSION, (byte)VER_GREATER_EQUAL),
                    VER_MINORVERSION, (byte)VER_GREATER_EQUAL),
                buildNumberMask, (byte)VER_GREATER_EQUAL);

            osvi.dwMajorVersion = wMajorVersion;
            osvi.dwMinorVersion = wMinorVersion;
            osvi.dwBuildNumber  = wBuildVersion;
            // osvi.wServicePackMajor = wServicePackMajor;

            return(VerifyVersionInfoW(ref osvi, VER_MAJORVERSION | VER_MINORVERSION | buildNumberMask, dwlConditionMask) != false);
        }
Exemplo n.º 8
0
 static extern bool VerifyVersionInfoW(ref OSVERSIONINFOEXW lpVersionInformation, uint dwTypeMask, ulong dwlConditionMask);
Exemplo n.º 9
0
 public static extern bool GetVersionExW(ref OSVERSIONINFOEXW osvi);
Exemplo n.º 10
0
 extern static int RtlGetVersion(ref OSVERSIONINFOEXW lpVersionInformation);
Exemplo n.º 11
0
 public static extern bool RtlGetVersion(ref OSVERSIONINFOEXW versionInfo);
 private static extern int RtlGetVersion(ref OSVERSIONINFOEXW versionInformation);
        /// <summary>
        /// Checks if the OS supports WAM (Web Account Manager)
        /// WAM Supported OS's are Windows 10 and above for Client, Windows 2019 and above for Server
        /// </summary>
        /// <returns>Returns <c>true</c> if the OS Version has WAM support</returns>
        public static bool IsWamSupportedOs()
        {
            try
            {
#if NET45
                var OsVersionInfo = new OSVERSIONINFOEXW {
                    dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEXW))
                };
#else
                var OsVersionInfo = new OSVERSIONINFOEXW {
                    dwOSVersionInfoSize = Marshal.SizeOf <OSVERSIONINFOEXW>()
                };
#endif
                if (RtlGetVersion(ref OsVersionInfo) == NT_STATUS_SUCCESS)
                {
                    switch (OsVersionInfo.wProductType)
                    {
                    //To filter client operating systems only, such as Windows 10 or Windows 11 Clients, use ProductType="1".
                    case VER_NT_WORKSTATION:
                        switch (OsVersionInfo.dwMajorVersion)
                        {
                        //https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version
                        //For Client (Windows 10 and 11) and for Server (Windows 2016 and above) Major version is 10.*
                        //Windows 10 Build Number 15063 is the minimum version where WAM is supported
                        case 10:
                            if (OsVersionInfo.dwBuildNumber >= WamSupportedWindows10BuildNumber)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }

                        default:
                            return(false);
                        }

                    //For server operating systems that are not domain controllers and for Windows 10 and Windows 11 multi-session, use ProductType="3".
                    //https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-firewall/create-wmi-filters-for-the-gpo
                    case VER_NT_SERVER:
                    case VER_NT_DOMAIN_CONTROLLER:
                        switch (OsVersionInfo.dwMajorVersion)
                        {
                        //https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version
                        //For Client (Windows 10 and 11) and for Server (Windows 2016 and above) Major version is 10.*
                        //Windows Server 2019 minimum build number is 17763
                        case 10:
                            if (OsVersionInfo.dwBuildNumber >= Windows2019BuildNumber)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }

                        default:
                            return(false);
                        }

                    default:
                        return(false);
                    }
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }