using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
namespace omrokMultimediaPlayer
{
public static class OmrokDynamicsSystemLibrary
{
//Processor ID
///<summary>
///Retrieving Processor Id.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_ProcID()
{
ManagementClass OmrokDynamicsProcID_MClass = new ManagementClass("win32_processor");
ManagementObjectCollection OmrokDynamicsProcID_MOCollection = OmrokDynamicsProcID_MClass.GetInstances();
String OmrokDynamicsProcId_Strng = String.Empty;
foreach (ManagementObject OmrokDynamicsProcID_MObject in OmrokDynamicsProcID_MOCollection)
{
OmrokDynamicsProcId_Strng = OmrokDynamicsProcID_MObject.Properties["processorID"].Value.ToString();
break;
}
return OmrokDynamicsProcId_Strng;
}
//Hard Drive Number
///<summary>
///Retrieving HDD Serial No.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_HDDNumber()
{
ManagementClass OmrokDynamicsHDD_MClass = new ManagementClass("win32_LogicalDisk");
ManagementObjectCollection OmrokDynamicsHDD_MOCollection = OmrokDynamicsHDD_MClass.GetInstances();
string OmrokDynamicsHDD_Rslt = "";
foreach (ManagementObject OmrokDynamicsHDD_MObject in OmrokDynamicsHDD_MOCollection)
{
OmrokDynamicsHDD_Rslt += Convert.ToString(OmrokDynamicsHDD_MObject["VolumeSerialNumber"]);
}
return OmrokDynamicsHDD_Rslt;
}
//MAC Address
///<summary>
///Retrieving System MAC Address
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_MACAddress()
{
ManagementClass OmrokDynamicsMAC_MClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection OmrokDynamicsMAC_MOCollection = OmrokDynamicsMAC_MClass.GetInstances();
string OmrokDynamicsMACAddress = String.Empty;
foreach (ManagementObject OmrokDynamicsMAC_MObject in OmrokDynamicsMAC_MOCollection)
{
if (OmrokDynamicsMACAddress == String.Empty)
{
if ((bool)OmrokDynamicsMAC_MObject["IPEnabled"] == true)
{
OmrokDynamicsMACAddress = OmrokDynamicsMAC_MObject["MacAddress"].ToString();
}
}
OmrokDynamicsMAC_MObject.Dispose();
}
OmrokDynamicsMACAddress = OmrokDynamicsMACAddress.Replace(":", "");
return OmrokDynamicsMACAddress;
}
//Motherboard Manufacturer
///<summary>
///Retrieving Motherboard Manufacturer
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_BoardMaker()
{
ManagementObjectSearcher OmrokDynamicsBM_MOSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard");
foreach (ManagementObject OmrokDynamicsBM_wmi in OmrokDynamicsBM_MOSearcher.Get())
{
try
{
return OmrokDynamicsBM_wmi.GetPropertyValue("Manufacturer").ToString();
}
catch { }
}
return "Board Maker: Unknown";
}
//Motherboard Product ID
///<summary>
///Retrieving Motherboard Product Id.
///</summary>
///<returns></returns>
public static string GETOmrokDynamics_BoardProductId()
{
ManagementObjectSearcher OmrokDynamicsBpID_MOSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard");
foreach (ManagementObject OmrokDynamicsBpID_wmi in OmrokDynamicsBpID_MOSearcher.Get())
{
try
{
return OmrokDynamicsBpID_wmi.GetPropertyValue("Product").ToString();
}
catch { }
}
return "Product: Unknown";
}
//ROM Drive
///<summary>
///Retrieving CD-DVD Drive Path.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_RomDrive()
{
ManagementObjectSearcher OmrokDynamicsROMDrive_MOSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_CDROMDrive");
foreach (ManagementObject OmrokDynamicsROMDrive_wmi in OmrokDynamicsROMDrive_MOSearcher.Get())
{
try
{
return OmrokDynamicsROMDrive_wmi.GetPropertyValue("Drive").ToString();
}
catch { }
}
return "CD ROM Drive Letter: Unknown";
}
//BIOS Manufacturer
///<summary>
///Retrieving BIOS Maker
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_BIOSmaker()
{
ManagementObjectSearcher OmrokDynamicsBIOSmaker_searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS");
foreach (ManagementObject OmrokDynamicsBIOSmaker_wmi in OmrokDynamicsBIOSmaker_searcher.Get())
{
try
{
return OmrokDynamicsBIOSmaker_wmi.GetPropertyValue("Manufacturer").ToString();
}
catch { }
}
return "BIOS Maker: Unknown";
}
//BIOS Number
///<summary>
///Retrieving BIOS Serial No.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_BIOSNo()
{
ManagementObjectSearcher OmrokDynamicsBIOSNo_MOSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS");
foreach (ManagementObject OmrokDynamicsBIOSNo_wmi in OmrokDynamicsBIOSNo_MOSearcher.Get())
{
try
{
return OmrokDynamicsBIOSNo_wmi.GetPropertyValue("SerialNumber").ToString();
}
catch { }
}
return "BIOS Serial Number: Unknown";
}
//BIOS Information
///<summary>
///Retrieving BIOS Caption.
///</summary>
///<returns></returns>
public static String GetOmrokDynamics_BIOScaption()
{
ManagementObjectSearcher OmrokDynamicsBIOScap_MOSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS");
foreach (ManagementObject OmrokDynamicsBIOScap_wmi in OmrokDynamicsBIOScap_MOSearcher.Get())
{
try
{
return OmrokDynamicsBIOScap_wmi.GetPropertyValue("Caption").ToString();
}
catch { }
}
return "BIOS Caption: Unknown";
}
//Computer User Account Name
///<summary>
///Retrieving System Account Name.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_UserAccountName()
{
ManagementObjectSearcher OmrokDynamicsUserAccountName_MOSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_UserAccount");
foreach (ManagementObject OmrokDynamicsUserAccountName_wmi in OmrokDynamicsUserAccountName_MOSearcher.Get())
{
try
{
return OmrokDynamicsUserAccountName_wmi.GetPropertyValue("Name").ToString();
}
catch { }
}
return "User Account Name: Unknown";
}
//Current Physical Memory
///<summary>
///Retrieving Physical Memory.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_PhysicalMemory()
{
ManagementScope OmrokDynamicsPhyscalMem_MScope = new ManagementScope();
ObjectQuery OmrokDynamicsPhyscalMem_OQuery = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
ManagementObjectSearcher OmrokDynamicsPhyscalMem_OSearcher = new ManagementObjectSearcher(OmrokDynamicsPhyscalMem_MScope, OmrokDynamicsPhyscalMem_OQuery);
ManagementObjectCollection OmrokDynamicsPhysicalMem_oCollection = OmrokDynamicsPhyscalMem_OSearcher.Get();
long OmrokDynamicsPhysicalMem_MemSize = 0;
long OmrokDynamicsPhysicalMem_mCap = 0;
//In case more than one Memory Stick are installed
foreach (ManagementObject OmrokDynamicsPhysicalMem_obj in OmrokDynamicsPhysicalMem_oCollection)
{
OmrokDynamicsPhysicalMem_mCap = Convert.ToInt64(OmrokDynamicsPhysicalMem_obj["Capacity"]);
OmrokDynamicsPhysicalMem_MemSize += OmrokDynamicsPhysicalMem_mCap;
}
OmrokDynamicsPhysicalMem_MemSize = (OmrokDynamicsPhysicalMem_MemSize / 1024) / 1024;
return OmrokDynamicsPhysicalMem_MemSize.ToString() + "MB";
}
//RAM Slots
///<summary>
///Retrieving No. of RAM Slots on Motherboard.
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_NoRamSlots()
{
int OmrokDynamicsNoRamSlots_MemSlots = 0;
ManagementScope OmrokDynamicsNoRamSlots_MScope = new ManagementScope();
ObjectQuery OmrokDynamicsNoRamSlots_OQuery2 = new ObjectQuery("SELECT MemoryDevices FROM Win32_PhysicalMemoryArray");
ManagementObjectSearcher OmrokDynamicsNoRamSlots_oSearcher2 = new ManagementObjectSearcher(OmrokDynamicsNoRamSlots_MScope, OmrokDynamicsNoRamSlots_OQuery2);
ManagementObjectCollection OmrokDynamicsNoRamSlots_oCollection2 = OmrokDynamicsNoRamSlots_oSearcher2.Get();
foreach (ManagementObject OmrokDynamicsNoRamSlots_obj in OmrokDynamicsNoRamSlots_oCollection2)
{
OmrokDynamicsNoRamSlots_MemSlots = Convert.ToInt32(OmrokDynamicsNoRamSlots_obj["MemoryDevices"]);
}
return OmrokDynamicsNoRamSlots_MemSlots.ToString();
}
//CPU Mnaufacturer
///<summary>
///method for retrieving the CPU Manufacturer
///</summary>
///<returns>CPU Manufacturer</returns>
public static String GETOmrokDynamics_CPUManufacturer()
{
string OmrokDynamicsCPUManufacturer = String.Empty;
//CREATE AN INSTANCE OF THE MANAGEMENT CLASS WITH THE
//Win32_Processor class
ManagementClass OmrokDynamicsCPUManufacturer_mgmt = new ManagementClass("Win32_Processor");
//CREATE A ManagementObjectCollection TO LOOP THROUGH
ManagementObjectCollection OmrokDynamicsCPUManufacturer_objCol = OmrokDynamicsCPUManufacturer_mgmt.GetInstances();
//START LOOP FOR ALL PROCESSORS FOUND
foreach (ManagementObject OmrokDynamicsCPUManufacturer_obj in OmrokDynamicsCPUManufacturer_objCol)
{
if (OmrokDynamicsCPUManufacturer == String.Empty)
{
//ONLY RETURN MANUFACTURER FROM FIRST CPU
OmrokDynamicsCPUManufacturer = OmrokDynamicsCPUManufacturer_obj.Properties["Manufacturer"].Value.ToString();
}
}
return OmrokDynamicsCPUManufacturer;
}
//CPU Current Clock Speed
///<summary>
///METHOD TO RETRIEVE THE CPU CURRENT CLOCK SPEED USING wmi CLASS
///</summary>
///<returns>Clock speed</returns>
public static int GETOmrokDynamics_CPUCurrentClockSpeed()
{
int OmrokDynamicsCPUSpeed = 0;
//CREATE AN INSTANCE OF THE MANAGEMENT CLASS WITH TRHE Win32_Processor class
ManagementClass OmrokDynamicsCPUSpeed_mgmt = new ManagementClass("Win32_Processor");
//CREATE A ManagementObjectCollection TO LOOP THROUGH
ManagementObjectCollection OmrokDynamicsCPUSpeed_objCol = OmrokDynamicsCPUSpeed_mgmt.GetInstances();
//START LOOP FOR ALL PROCESSORS FOUND
foreach (ManagementObject OmrokDynamicsCPUSpeed_obj in OmrokDynamicsCPUSpeed_objCol)
{
if (OmrokDynamicsCPUSpeed == 0)
{
//ONLY RETURN cpuStatus FROM FIRST CPU
OmrokDynamicsCPUSpeed = Convert.ToInt32(OmrokDynamicsCPUSpeed_obj.Properties["CurrentClockSpeed"].Value.ToString());
}
}
//RETURN THE STATUS
return OmrokDynamicsCPUSpeed;
}
//Default IP Gateway
///<summary>
///method to retrieve the network adapters default IP Gateway using WMI
///</summary>
///<returns>adapters default IP gateway</returns>
public static String GETOmrokDynamics_DefaultIPGateway()
{
//CREATE OUT MANAGEMENT CLASS OBJECT USING THE Win32_NetworkAdapterConfiguration class TO GET THE ATTRIBUTES OF THE NETWORK ADAPTER
ManagementClass OmrokDynamicsDefaultIPGateway_mgmt = new ManagementClass("Win32_NetworkAdapterConfiguration");
//CREATE ManagementObjectCollection class TO GET THE ATTRIBUTES WITH
ManagementObjectCollection OmrokDynamicsDefaultIPGateway_objCol = OmrokDynamicsDefaultIPGateway_mgmt.GetInstances();
string OmrokDynamicsDefaultIPGateway = String.Empty;
//LOOP THROUGH ALL THE OBJECTS WI FIND
foreach (ManagementObject OmrokDynamicsDefaultIPGateway_obj in OmrokDynamicsDefaultIPGateway_objCol)
{
//ONLY RETURN MAC ADDRESS FROM FIRST CARD
if (OmrokDynamicsDefaultIPGateway == String.Empty)
{
//GRAB THE VALUE FROM THE FIRST NETWORK ADAPTER WE FIND
//YOU CAN CHANGE THE STRING TO AN ARRAY AND GET ALL NETWORK ADAPTERS FOUND AS WELL
//CHECK TO SEE IF THE ADAPTER'S IPEnabled EQUALS TRUE
if ((bool)OmrokDynamicsDefaultIPGateway_obj["IPEnabled"] == true)
{
OmrokDynamicsDefaultIPGateway = OmrokDynamicsDefaultIPGateway_obj["DefaultIPGateway"].ToString();
}
}
//DISPOSE OF OBJECT
OmrokDynamicsDefaultIPGateway_obj.Dispose();
}
//REPLACE THE ":" WITH EMPTY SPACE, THIS COULD ALSO BE REMOVED IF YOU WISH
OmrokDynamicsDefaultIPGateway = OmrokDynamicsDefaultIPGateway = OmrokDynamicsDefaultIPGateway.Replace(":", "");
//RETURN THE MAC ADDRESS
return OmrokDynamicsDefaultIPGateway;
}
//CPU Speed in GHz per Second
///<summary>
///Retrieve CPU Speed
///</summary>
///<returns></returns>
public static Double? GETOmrokDynamics_CpuSpeedInGHz()
{
double? OmrokDynamicsCPUGHz = null;
using (ManagementClass OmrokDynamicsCPUGHz_mc = new ManagementClass("Win32_Processor"))
{
foreach (ManagementObject OmrokDynamicsCPUGHz_mo in OmrokDynamicsCPUGHz_mc.GetInstances())
{
OmrokDynamicsCPUGHz = 0.001 * (UInt32)OmrokDynamicsCPUGHz_mo.Properties["CurrentClockSpeed"].Value;
break;
}
}
return OmrokDynamicsCPUGHz;
}
//Current Computer Language
///<summary>
///Reytrieving Current Language
///</summary>
///<returns></returns>
public static string GETOmrokDynamics_CurrentLanguage()
{
ManagementObjectSearcher OmrokDynamicsCurrentLanguage_searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS");
foreach (ManagementObject OmrokDynamicsCurrentLanguage_wmi in OmrokDynamicsCurrentLanguage_searcher.Get())
{
try
{
return OmrokDynamicsCurrentLanguage_wmi.GetPropertyValue("CurrentLanguage").ToString();
}
catch { }
}
return "BIOS Maker: Unknown";
}
//Processor Information
///<summary>
///Retrieving Processor Information
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_ProcessorInformation()
{
ManagementClass OmrokDynamicsProcessorInformation_mc = new ManagementClass("Win32_processor");
ManagementObjectCollection OmrokDynamicsProcessorInformation_moc = OmrokDynamicsProcessorInformation_mc.GetInstances();
String OmrokDynamicsProcessorInformation = String.Empty;
foreach (ManagementObject OmrokDynamicsProcessorInformation_mo in OmrokDynamicsProcessorInformation_moc)
{
string OmrokDynamics_name = (string)OmrokDynamicsProcessorInformation_mo["Name"];
OmrokDynamics_name = OmrokDynamics_name.Replace("(TM)", "™").Replace("(tm)", "™").Replace("(R)", "®").Replace("(r)", "®").Replace("(C)", "©").Replace("(c)", "©").Replace(" ", " ").Replace(" ", " ");
OmrokDynamicsProcessorInformation = OmrokDynamics_name + "," + (string)OmrokDynamicsProcessorInformation_mo["Caption"] + "," + (string)OmrokDynamicsProcessorInformation_mo["SocketDesignation"];
OmrokDynamicsProcessorInformation_mo.Properties["Name"].Value.ToString();
break;
}
return OmrokDynamicsProcessorInformation;
}
//Computer Name
///<summary>
///Retrieving Computer Name
///</summary>
///<returns></returns>
public static String GETOmrokDynamics_ComputerName()
{
ManagementClass OmrokDynamicsComputerName_mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection OmrokDynamicsComputerName_moc = OmrokDynamicsComputerName_mc.GetInstances();
String OmrokDynamicsComputerName_info = String.Empty;
foreach (ManagementObject OmrokDynamicsComputerName_mo in OmrokDynamicsComputerName_moc)
{
OmrokDynamicsComputerName_info = (string)OmrokDynamicsComputerName_mo["Name"];
//mo.Properties["Name"].Value.ToString();
//break;
}
return OmrokDynamicsComputerName_info;
}
//Get current Operating System
}
}
In this C# class, we create functions that help us invoke all system information such as Processor ID, Motherboard information, computer name etc...
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.