Tag: machine

C#

How to check the machine type in C#

public enum ChassisTypes { Other = 1, Unknown, Desktop, LowProfileDesktop, PizzaBox, MiniTower, Tower, Portable, Laptop, Notebook, Handheld, DockingStation, AllInOne, SubNotebook, SpaceSaving, LunchBox, MainSystemChassis, ExpansionChassis, SubChassis, BusExpansionChassis, PeripheralChassis, StorageChassis, RackMountChassis, SealedCasePC }   public ChassisTypes GetCurrentChassisType() { try { ManagementClass mc = new ManagementClass("Win32_SystemEnclosure"); foreach (ManagementObject mo in mc.GetInstances()) foreach (int i in (UInt16[])(mo["ChassisTypes"])) if (i …

C#

Check whether the system is 32 bit or 64 bit

Check if the system is 64 bit. public Boolean Is64Bit_1() { return System.Environment.GetEnvironmentVariable("ProgramW6432") != ""; }public Boolean Is64Bit_1() { return System.Environment.GetEnvironmentVariable("ProgramW6432") != ""; } Check if specified process is 64 bit. [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true, CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)] [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)] public static extern bool IsWow64Process([System.Runtime.InteropServices.In] IntPtr hProcess, [System.Runtime.InteropServices.Out] out Boolean lpSystemInfo);   public Boolean Is64Bit_2() …

C#

Get machine’s MAC address using C#

Let’s see some C# code that gets the MAC Address of the network interface controller that is up. 1 2 3 4 5 6 7 8 9 String mac = ""; foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { if (ni.OperationalStatus == OperationalStatus.Up) { mac = ni.GetPhysicalAddress().ToString(); break; } }String mac = ""; foreach (NetworkInterface ni in …