C# get computer Processor information

csharp get pc processor One line code to find computer Processor information, whether its system type 32-bit or 64-bit operating system. From system class Environment, retrieve all the system information including processor information. Included work around separate class to get the same Processor information.

Download

Example Source Snippets - GetProcessor.zip

namespace : using System;

Environment Retrive Processor information


                     #region  Get PC Processor in one line
          
                    if (Environment.Is64BitProcess)           
                        label1.Text = "x64 Bit based Processor";          
                    else           
                        label1.Text = "x32 Bit based Processor";           

                    #endregion
       
                 

Work around separate class to get the same Processor information


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace GetProcessor
{   
    public static class ProcessorClass
    {
        [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool Is64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);

        public static bool IsProcessor64Bit()
        {
            if (IntPtr.Size == 8 || (IntPtr.Size == 4 && IsProcessor32Bit()))           
                return true;           
            else           
                return false;            
        }

        private static bool IsProcessor32Bit()
        {
            bool retVal;
            Is64Process(Process.GetCurrentProcess().Handle, out retVal);
            return retVal;
        }
    }
}

       
                 

smartsnipps.ecomparefiles.com © 2019, All Rights Reserved | Disclaimer: smartsnipps.eCompareFiles.com is free to use any code snippets without guarantee