Академический Документы
Профессиональный Документы
Культура Документы
using
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Diagnostics;
System.Linq;
System.Management;
System.Runtime.InteropServices;
System.Security.Cryptography;
System.Text;
System.Windows;
SlarkStuff.DllHelpers;
SlarkStuff.ErrorReporting;
namespace SlarkStuff.HardwareIdExtractor
{
public static class MyHardwareIdExtractor
{
#region HardwareIDExtractorC.dll
public enum OsMemType : byte // OSMemType used by SystemMemStatus
{
MMemoryLoad = 1, // total memory used in percents (%)
MTotalPhys = 2, // total physical memory in bytes
MAvailPhys = 3, // available physical memory (bytes)
MTotalPageFile = 4, // total page file in (bytes)
MAvailPageFile = 5, // available page file (bytes)
MTotalVirtual = 6, // total virtual memory in bytes
MAvailVirtual = 7 // available virtual memory (bytes)
}
public enum ProcMemType : byte // ProcMemType used by ProcessMemStatus
{
PWorkingSetSize = 1, // the current working set size, in bytes
PPageFaultCount = 2, // the number of page faults
PPeakWorkingSetSize = 3, // the peak working set size, in bytes
PQuotaPeakPagedPoolUsage = 4, // the peak paged pool usage, in bytes
PQuotaPagedPoolUsage = 5, // the current paged pool usage, in bytes
PQuotaPeakNonPagedPool = 6, // the peak nonpaged pool usage, in byte
s
PQuotaNonPagedPoolUsg = 7, // the current nonpaged pool usage, in by
tes
PPageFileUsage = 8, // the current space allocated for the pagefile,
in bytes; those pages may or may not be in memory
PPeakPagefileUsage = 9, // the peak space allocated for the pagefile
, in bytes
}
private static class Native //! NATIVE
{
private const string DllFolder = "libs\\libHardwareIdExtractor\\";
private const string DllName = "HardwareIDExtractorC.dll";
private const string DllPath = /*DllFolder +*/ DllName;
//- SOURCE: http://stackoverflow.com/questions/28117178/how-to-fix-n
tdll-dll-appcrash-with-hardware-id-extractor/28118829?noredirect=1#28118829
//- SOURCE: http://www.soft.tahionic.com/download-hdd_id/hardware%20
id%20programming%20source%20code/exported%20functions%20for%20non-Delphi.html
//- SOURCE: http://www.soft.tahionic.com/download-hdd_id/hardware%20
id%20programming%20source%20code/exported%20functions%20for%20Delphi.html
//- SOURCE: http://www.soft.tahionic.com/download-hdd_id/articles/De
lphi%20to%20C%20type%20conversion.html
//- SOURCE: http://www.soft.tahionic.com/download-hdd_id/hardware%20
id%20programming%20source%20code/CPU_mask.html
//! CPU
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, C
harSet = CharSet.Ansi, EntryPoint = "CPUFamily")]
internal static extern IntPtr CPUFamily(); // get CPUU identifier fr
om the windows registry
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, C
harSet = CharSet.Ansi, EntryPoint = "GetCPUVendor")]
internal static extern IntPtr GetCPUVendor(); // new GetCPUVendor fu
nction, reported to work with D7 and D2009
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, E
ntryPoint = "GetCPUSpeed")] //! free
internal static extern double GetCPUSpeed(int speed = 200); // the h
igher the delay, the accurate the result (default = 200ms)
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, E
ntryPoint = "IsIntel64BitCPU")] //! free
internal static extern bool IsIntel64BitCPU(); // detects IA64 proce
ssors
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, E
ntryPoint = "GetCpuTheoreticSpeed")]
internal static extern int GetCpuTheoreticSpeed(); // get CPU speed
(in MHz)
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, E
ntryPoint = "IsCPUIDAvailable")] //! free
internal static extern bool IsCPUIDAvailable();
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, C
harSet = CharSet.Ansi, EntryPoint = "GetCPUID")]
internal static extern IntPtr GetCPUID(ushort coreMask); // get the
ID of the specified logical CPU, max coreMask = GetCPUCount()
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, C
harSet = CharSet.Ansi, EntryPoint = "GetCpuIdNow")]
internal static extern IntPtr GetCpuIdNow(); // get the ID of the fi
rst available logical CPU
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, E
ntryPoint = "GetCPUCount")] //! free
internal static extern int GetCPUCount(); // the number of LOGICAL p
rocessors in the current group
//! SYSTEM RAM
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, E
ntryPoint = "SystemMemStatus")] //! free
internal static extern uint SystemMemStatus(OsMemType osMemType); //
in Bytes, Limited by the capacity of the OS (32bits OSs will report max 2GB)
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall, C
}
}
public static class VirtualRam //! VIRTUAL RAM
{
public static uint GetPageSizeNative()
{
//! returns uint in MB
return Native.GetPageSize();
}
public static int GetMemGranularityNative()
{
//! returns int in KB
return Native.GetMemGranularity();
}
}
public static class AdvancedRam //! RAM - Advanced stuff
{
public static uint GetLowAddrNative()
{
return Native.GetLowAddr();
}
public static uint GetHiAddrNative()
{
return Native.GetHiAddr();
}
public static void TrimWorkingSetNative()
{
//! EXTREMELY USEFUL FUNCTION
if (!Internal.EnterKey()) return;
Native.TrimWorkingSet();
}
}
public static class HardDiskDrive //! HDD
{
public static string GetPartitionID(string partition = "C:\\")
{
if (!Internal.EnterKey()) return null;
var ptr = Native.GetPartitionID(partition);
var partId = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns string formatted Win32_LogicalDisk VolumeSerialNumbe
r
return partId;
}
public static string GetIdeSerialNumber(byte driveNumber)
{
if (!Internal.EnterKey()) return null;
var ptr = Native.GetIDESerialNumber(driveNumber);
var ideSerial = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns formatted hard drive unique ID:
return ideSerial;
}
}
public static class Bios //! BIOS (NEW!)
{
public static string BiosDate()
{
if (!Internal.EnterKey()) return null;
var ptr = Native.BiosDate();
var biosDate = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns a formatted string 02/05/10 (mm/dd/yy)
return biosDate;
}
public static string BiosVersion()
{
if (!Internal.EnterKey()) return null;
var ptr = Native.BiosVersion();
var biosVersion = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns a formatted string with lots of info
return biosVersion;
}
public static string BiosProductId()
{
if (!Internal.EnterKey()) return null;
var ptr = Native.BiosProductID();
var biosProductId = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns "System Version"
return biosProductId;
}
public static string BiosVideo()
{
if (!Internal.EnterKey()) return null;
var ptr = Native.BiosVideo();
var biosVideo = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns a formatted string 02/05/10 (mm/dd/yy)
return biosVideo;
}
}
public static class Utils //! UTILS
{
public static string GenerateHardwareReport()
{
if (!Internal.EnterKey()) return null;
var ptr = Native.GenerateHardwareReport();
var hardwareReport = Marshal.PtrToStringAnsi(ptr);
Native.ReleaseMemory(ptr);
//! returns a formatted hardware report (just like the free util
ity does)
return hardwareReport;
}
public static string FormatBytes(Int64 size, byte decimals)
{