コード例 #1
0
ファイル: Process.cs プロジェクト: zhangli0092/opennetcf
        private static uint GetPUserKData()
        {
            uint PUserKData = 0;

            NativeMethods.SystemInfo si = new NativeMethods.SystemInfo();
            NativeMethods.GetSystemInfo(out si);

            switch (si.ProcessorArchitecture)
            {
            case NativeMethods.ProcessorArchitecture.ARM:
                PUserKData = PUserKDataARM;
                break;

            //the "x86" constant is for all non-arm architectures so removed exception throw
            default:
                //case Core.ProcessorArchitecture.Intel:
                PUserKData = PUserKDataX86;
                break;

                //throw new NotSupportedException("Unsupported on current processor: " + EnumEx.GetName(typeof(Core.ProcessorArchitecture), si.wProcessorArchitecture));
            }

            return(PUserKData);
        }
コード例 #2
0
ファイル: OperatingSystem.cs プロジェクト: Sicos1977/AlphaFS
      private static void UpdateData()
      {
         NativeMethods.OsVersionInfoEx verInfo = new NativeMethods.OsVersionInfoEx();

         // Needed to prevent: System.Runtime.InteropServices.COMException:
         // The data area passed to a system call is too small. (Exception from HRESULT: 0x8007007A)
         verInfo.OSVersionInfoSize = Marshal.SizeOf(verInfo);

         NativeMethods.SystemInfo sysInfo = new NativeMethods.SystemInfo();
         NativeMethods.GetSystemInfo(ref sysInfo);

         if (!NativeMethods.GetVersionEx(ref verInfo))
            NativeError.ThrowException(Marshal.GetLastWin32Error());

         Debug.Assert(verInfo.MajorVersion == Environment.OSVersion.Version.Major);
         Debug.Assert(verInfo.MinorVersion == Environment.OSVersion.Version.Minor);
         Debug.Assert(verInfo.BuildNumber == Environment.OSVersion.Version.Build);

         _processorArchitecture = (EnumProcessorArchitecture)sysInfo.processorArchitecture;
         _servicePackVersion = new Version(verInfo.ServicePackMajor, verInfo.ServicePackMinor);
         _isServer = verInfo.ProductType == NativeMethods.VerNtDomainController || verInfo.ProductType == NativeMethods.VerNtServer;


         // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833%28v=vs.85%29.aspx

         // The following table summarizes the most recent operating system version numbers.
         //    Operating system	            Version number    Other
         // ================================================================================
         //    Windows 8.1                   6.3               OSVersionInfoEx.ProductType == VerNtWorkstation
         //    Windows Server 2012 R2        6.3               OSVersionInfoEx.ProductType != VerNtWorkstation
         //    Windows 8	                  6.2               OSVersionInfoEx.ProductType == VerNtWorkstation
         //    Windows Server 2012	         6.2               OSVersionInfoEx.ProductType != VerNtWorkstation
         //    Windows 7	                  6.1               OSVersionInfoEx.ProductType == VerNtWorkstation
         //    Windows Server 2008 R2	      6.1               OSVersionInfoEx.ProductType != VerNtWorkstation
         //    Windows Server 2008	         6.0               OSVersionInfoEx.ProductType != VerNtWorkstation  
         //    Windows Vista	               6.0               OSVersionInfoEx.ProductType == VerNtWorkstation
         //    Windows Server 2003 R2	      5.2               GetSystemMetrics(SM_SERVERR2) != 0
         //    Windows Home Server  	      5.2               OSVersionInfoEx.SuiteMask & VER_SUITE_WH_SERVER
         //    Windows Server 2003           5.2               GetSystemMetrics(SM_SERVERR2) == 0
         //    Windows XP 64-Bit Edition     5.2               (OSVersionInfoEx.ProductType == VerNtWorkstation) && (sysInfo.PaName == PaName.X64)
         //    Windows XP	                  5.1               Not applicable
         //    Windows 2000	               5.0               Not applicable


         if (verInfo.MajorVersion > 6)
            _enumOsName = EnumOsName.Later;

         else
            switch (verInfo.MajorVersion)
            {
                  #region Version 6

               case 6:
                  switch (verInfo.MinorVersion)
                  {
                        // Windows Vista or Windows Server 2008
                     case 0:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.WindowsVista
                           : EnumOsName.WindowsServer2008;
                        break;

                        // Windows 7 or Windows Server 2008 R2
                     case 1:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.Windows7
                           : EnumOsName.WindowsServer2008R2;
                        break;

                        // Windows 8 or Windows Server 2012
                     case 2:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.Windows8
                           : EnumOsName.WindowsServer2012;
                        break;

                        // Windows 8.1 or Windows Server 2012R2
                     case 3:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.Windows81
                           : EnumOsName.WindowsServer2012R2;
                        break;

                     default:
                        _enumOsName = EnumOsName.Later;
                        break;
                  }
                  break;

                  #endregion // Version 6

                  #region Version 5

               case 5:
                  switch (verInfo.MinorVersion)
                  {
                     case 0:
                        _enumOsName = EnumOsName.Windows2000;
                        break;

                     case 1:
                        _enumOsName = EnumOsName.WindowsXP;
                        break;

                     case 2:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation && _processorArchitecture == EnumProcessorArchitecture.X64)
                           ? EnumOsName.WindowsXP
                           : (verInfo.ProductType != NativeMethods.VerNtWorkstation)
                              ? EnumOsName.WindowsServer2003
                              : EnumOsName.Later;
                        break;

                     default:
                        _enumOsName = EnumOsName.Later;
                        break;
                  }
                  break;

                  #endregion // Version 5

               default:
                  _enumOsName = EnumOsName.Earlier;
                  break;
            }
      }
コード例 #3
0
        private void GetOSVersion()
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                NativeMethods.OSVersionInfoEx versionInfo = new NativeMethods.OSVersionInfoEx();
                versionInfo.dwOSVersionInfoSize = Marshal.SizeOf(versionInfo);
                NativeMethods.GetVersionEx(ref versionInfo);

                NativeMethods.SystemInfo sysInfo = new NativeMethods.SystemInfo();
                NativeMethods.GetSystemInfo(out sysInfo);
                NativeMethods.VersionNT             versionType  = (NativeMethods.VersionNT)versionInfo.wProductType;
                NativeMethods.ProcessorArchitecture architecture = (NativeMethods.ProcessorArchitecture)sysInfo.processorArchitecture;
                if (versionInfo.dwMajorVersion == 5)
                {
                    if (versionInfo.dwMinorVersion == 1)
                    {
                        this.operatingSystemVersion = "Windows XP";
                    }
                    else if (versionInfo.dwMinorVersion == 2)
                    {
                        int isServerR2 = NativeMethods.GetSystemMetrics((int)NativeMethods.SystemMetrics.ServerR2);
                        if (versionType == NativeMethods.VersionNT.Workstation && architecture == NativeMethods.ProcessorArchitecture.AMD64)
                        {
                            this.operatingSystemVersion = "Windows XP x64 Edition";
                        }
                        else if (versionType != NativeMethods.VersionNT.Workstation && isServerR2 == 0)
                        {
                            this.operatingSystemVersion = "Windows Server 2003";
                        }
                        else if (versionType == NativeMethods.VersionNT.Workstation && isServerR2 != 0)
                        {
                            this.operatingSystemVersion = "Windows Server 2003 R2";
                        }
                    }
                    else
                    {
                        this.operatingSystemVersion = "Windows 2000";
                    }
                }
                else if (versionInfo.dwMajorVersion == 6)
                {
                    if (versionInfo.dwMinorVersion == 0)
                    {
                        if (versionType == NativeMethods.VersionNT.Workstation)
                        {
                            this.operatingSystemVersion = "Windows Vista";
                        }
                        else
                        {
                            this.operatingSystemVersion = "Windows Server 2008";
                        }
                    }
                    else if (versionInfo.dwMinorVersion == 1)
                    {
                        if (versionType == NativeMethods.VersionNT.Workstation)
                        {
                            this.operatingSystemVersion = "Windows 7";
                        }
                        else
                        {
                            this.operatingSystemVersion = "Windows Server 2008 R2";
                        }
                    }
                    else
                    {
                        if (versionType == NativeMethods.VersionNT.Workstation)
                        {
                            this.operatingSystemVersion = "Windows 8";
                        }
                        else
                        {
                            this.operatingSystemVersion = "Windows Server 2012";
                        }
                    }
                }
                else
                {
                    this.operatingSystemVersion = "Unsupported Windows NT version";
                }

                if (Environment.OSVersion.ServicePack.Length > 0)
                {
                    this.operatingSystemVersion = this.operatingSystemVersion + " " + Environment.OSVersion.ServicePack;
                }

                this.operatingSystemVersion += " " + string.Format(CultureInfo.InvariantCulture, "({0}.{1}.{2})", versionInfo.dwMajorVersion, versionInfo.dwMinorVersion, versionInfo.dwBuildNumber);
                this.operatingSystemVersion += " " + architecture.ToString().ToLowerInvariant();
            }
        }
コード例 #4
0
        private static void UpdateData()
        {
            NativeMethods.OsVersionInfoEx verInfo = new NativeMethods.OsVersionInfoEx();

            // Needed to prevent: System.Runtime.InteropServices.COMException:
            // The data area passed to a system call is too small. (Exception from HRESULT: 0x8007007A)
            verInfo.OSVersionInfoSize = Marshal.SizeOf(verInfo);

            NativeMethods.SystemInfo sysInfo = new NativeMethods.SystemInfo();
            NativeMethods.GetSystemInfo(ref sysInfo);

            if (!NativeMethods.GetVersionEx(ref verInfo))
            {
                NativeError.ThrowException(Marshal.GetLastWin32Error());
            }

            Debug.Assert(verInfo.MajorVersion == Environment.OSVersion.Version.Major);
            Debug.Assert(verInfo.MinorVersion == Environment.OSVersion.Version.Minor);
            Debug.Assert(verInfo.BuildNumber == Environment.OSVersion.Version.Build);

            _processorArchitecture = (EnumProcessorArchitecture)sysInfo.processorArchitecture;
            _servicePackVersion    = new Version(verInfo.ServicePackMajor, verInfo.ServicePackMinor);
            _isServer = verInfo.ProductType == NativeMethods.VerNtDomainController || verInfo.ProductType == NativeMethods.VerNtServer;


            // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833%28v=vs.85%29.aspx

            // The following table summarizes the most recent operating system version numbers.
            //    Operating system	            Version number    Other
            // ================================================================================
            //    Windows 8.1                   6.3               OSVersionInfoEx.ProductType == VerNtWorkstation
            //    Windows Server 2012 R2        6.3               OSVersionInfoEx.ProductType != VerNtWorkstation
            //    Windows 8	                  6.2               OSVersionInfoEx.ProductType == VerNtWorkstation
            //    Windows Server 2012	         6.2               OSVersionInfoEx.ProductType != VerNtWorkstation
            //    Windows 7	                  6.1               OSVersionInfoEx.ProductType == VerNtWorkstation
            //    Windows Server 2008 R2	      6.1               OSVersionInfoEx.ProductType != VerNtWorkstation
            //    Windows Server 2008	         6.0               OSVersionInfoEx.ProductType != VerNtWorkstation
            //    Windows Vista	               6.0               OSVersionInfoEx.ProductType == VerNtWorkstation
            //    Windows Server 2003 R2	      5.2               GetSystemMetrics(SM_SERVERR2) != 0
            //    Windows Home Server         5.2               OSVersionInfoEx.SuiteMask & VER_SUITE_WH_SERVER
            //    Windows Server 2003           5.2               GetSystemMetrics(SM_SERVERR2) == 0
            //    Windows XP 64-Bit Edition     5.2               (OSVersionInfoEx.ProductType == VerNtWorkstation) && (sysInfo.PaName == PaName.X64)
            //    Windows XP	                  5.1               Not applicable
            //    Windows 2000	               5.0               Not applicable


            if (verInfo.MajorVersion > 6)
            {
                _enumOsName = EnumOsName.Later;
            }

            else
            {
                switch (verInfo.MajorVersion)
                {
                    #region Version 6

                case 6:
                    switch (verInfo.MinorVersion)
                    {
                    // Windows Vista or Windows Server 2008
                    case 0:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.WindowsVista
                           : EnumOsName.WindowsServer2008;
                        break;

                    // Windows 7 or Windows Server 2008 R2
                    case 1:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.Windows7
                           : EnumOsName.WindowsServer2008R2;
                        break;

                    // Windows 8 or Windows Server 2012
                    case 2:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.Windows8
                           : EnumOsName.WindowsServer2012;
                        break;

                    // Windows 8.1 or Windows Server 2012R2
                    case 3:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation)
                           ? EnumOsName.Windows81
                           : EnumOsName.WindowsServer2012R2;
                        break;

                    default:
                        _enumOsName = EnumOsName.Later;
                        break;
                    }
                    break;

                    #endregion // Version 6

                    #region Version 5

                case 5:
                    switch (verInfo.MinorVersion)
                    {
                    case 0:
                        _enumOsName = EnumOsName.Windows2000;
                        break;

                    case 1:
                        _enumOsName = EnumOsName.WindowsXP;
                        break;

                    case 2:
                        _enumOsName = (verInfo.ProductType == NativeMethods.VerNtWorkstation && _processorArchitecture == EnumProcessorArchitecture.X64)
                           ? EnumOsName.WindowsXP
                           : (verInfo.ProductType != NativeMethods.VerNtWorkstation)
                              ? EnumOsName.WindowsServer2003
                              : EnumOsName.Later;
                        break;

                    default:
                        _enumOsName = EnumOsName.Later;
                        break;
                    }
                    break;

                    #endregion // Version 5

                default:
                    _enumOsName = EnumOsName.Earlier;
                    break;
                }
            }
        }