Last active
January 16, 2018 14:45
-
-
Save alexsandro-xpt/d839345d180273bcda6fccac870c5068 to your computer and use it in GitHub Desktop.
Get Processor data without dotnet WMI services.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Reflection; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Runtime.InteropServices; | |
| // Referências: | |
| // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724423(v=vs.85).aspx | |
| // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx | |
| // https://www.codeproject.com/Articles/1285/Calling-API-functions-using-C | |
| // https://pradhananand.wordpress.com/2014/12/31/pinvoke-calling-win32-api-from-c/ | |
| // https://github.com/sebhildebrandt/systeminformation | |
| namespace CpuRevision | |
| { | |
| [StructLayout(LayoutKind.Sequential)] | |
| public struct SystemInfo | |
| { | |
| public ProcessorArchitecture ProcessorArchitecture; // WORD | |
| public uint PageSize; // DWORD | |
| public IntPtr MinimumApplicationAddress; // (long)void* | |
| public IntPtr MaximumApplicationAddress; // (long)void* | |
| public IntPtr ActiveProcessorMask; // DWORD* | |
| public uint NumberOfProcessors; // DWORD (WTF) | |
| public uint ProcessorType; // DWORD | |
| public uint AllocationGranularity; // DWORD | |
| public ushort ProcessorLevel; // WORD | |
| public ushort ProcessorRevision; // WORD | |
| } | |
| class Program | |
| { | |
| [DllImport("kernel32")] | |
| static extern void GetSystemInfo(ref SystemInfo pSI); | |
| static void Main(string[] args) | |
| { | |
| SystemInfo pSI = new SystemInfo(); | |
| GetSystemInfo(ref pSI); | |
| Display(pSI); | |
| } | |
| static void Display(SystemInfo systemInfo) | |
| { | |
| Console.WriteLine("ActiveProcessorMask: " + systemInfo.ActiveProcessorMask); | |
| Console.WriteLine("AllocationGranularity: " + systemInfo.AllocationGranularity); | |
| Console.WriteLine("MaximumApplicationAddress: " + systemInfo.MaximumApplicationAddress); | |
| Console.WriteLine("NumberOfProcessors: " + systemInfo.NumberOfProcessors); | |
| Console.WriteLine("PageSize: " + systemInfo.PageSize); | |
| Console.WriteLine("ProcessorArchitecture: " + systemInfo.ProcessorArchitecture); | |
| Console.WriteLine("ProcessorLevel: " + systemInfo.ProcessorLevel); | |
| Console.WriteLine("ProcessorRevision: " + systemInfo.ProcessorRevision); | |
| Console.WriteLine("ProcessorType: " + systemInfo.ProcessorType); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment