using System; using System.Runtime.InteropServices; using System.Text; using Vanara.Extensions; using static Vanara.PInvoke.FunctionHelper; using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; namespace Vanara.PInvoke { public static partial class Kernel32 { /// The maximum computername length. public const uint MAX_COMPUTERNAME_LENGTH = 15; /// Specifies a type of computer name. // typedef enum _COMPUTER_NAME_FORMAT { ComputerNameNetBIOS, ComputerNameDnsHostname, ComputerNameDnsDomain, // ComputerNameDnsFullyQualified, ComputerNamePhysicalNetBIOS, ComputerNamePhysicalDnsHostname, ComputerNamePhysicalDnsDomain, // ComputerNamePhysicalDnsFullyQualified, ComputerNameMax} COMPUTER_NAME_FORMAT; https://msdn.microsoft.com/en-us/library/windows/desktop/ms724224(v=vs.85).aspx [PInvokeData("Winbase.h", MSDNShortId = "ms724224")] public enum COMPUTER_NAME_FORMAT { /// /// The NetBIOS name of the local computer or the cluster associated with the local computer. This name is limited to /// MAX_COMPUTERNAME_LENGTH + 1 characters and may be a truncated version of the DNS host name. For example, if the DNS host name /// is "corporate-mail-server", the NetBIOS name would be "corporate-mail-". /// ComputerNameNetBIOS, /// The DNS name of the local computer or the cluster associated with the local computer. ComputerNameDnsHostname, /// The name of the DNS domain assigned to the local computer or the cluster associated with the local computer. ComputerNameDnsDomain, /// /// /// The fully qualified DNS name that uniquely identifies the local computer or the cluster associated with the local computer. /// /// /// This name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. For example, if /// the DNS host name is "corporate-mail-server" and the DNS domain name is "microsoft.com", the fully qualified DNS name is "corporate-mail-server.microsoft.com". /// /// ComputerNameDnsFullyQualified, /// The NetBIOS name of the local computer. On a cluster, this is the NetBIOS name of the local node on the cluster. ComputerNamePhysicalNetBIOS, /// The DNS host name of the local computer. On a cluster, this is the DNS host name of the local node on the cluster. ComputerNamePhysicalDnsHostname, /// /// The name of the DNS domain assigned to the local computer. On a cluster, this is the DNS domain of the local node on the cluster. /// ComputerNamePhysicalDnsDomain, /// /// The fully qualified DNS name that uniquely identifies the computer. On a cluster, this is the fully qualified DNS name of the /// local node on the cluster. The fully qualified DNS name is a combination of the DNS host name and the DNS domain name, using /// the form HostName.DomainName. /// ComputerNamePhysicalDnsFullyQualified, /// Not used. ComputerNameMax, } /// Identifier of a firmware table provider for calls to EnumSystemFirmwareTables. public enum FirmwareTableProviderId : uint { /// The ACPI firmware table provider. ACPI = (byte)'A' << 24 | (byte)'C' << 16 | (byte)'P' << 8 | (byte)'I', /// The raw firmware table provider. Not supported for UEFI systems; use 'RSMB' instead. FIRM = (byte)'F' << 24 | (byte)'I' << 16 | (byte)'R' << 8 | (byte)'M', /// The raw SMBIOS firmware table provider. RSMB = (byte)'R' << 24 | (byte)'S' << 16 | (byte)'M' << 8 | (byte)'B' } /// /// Represents the relationship between the processor set identified in the corresponding SYSTEM_LOGICAL_PROCESSOR_INFORMATION /// or SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure. /// // typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP { RelationProcessorCore, RelationNumaNode, RelationCache, RelationProcessorPackage, // RelationGroup, RelationAll = 0xffff} LOGICAL_PROCESSOR_RELATIONSHIP; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684197(v=vs.85).aspx [PInvokeData("WinNT.h", MSDNShortId = "ms684197")] public enum LOGICAL_PROCESSOR_RELATIONSHIP : uint { /// The specified logical processors share a single processor core. RelationProcessorCore, /// The specified logical processors are part of the same NUMA node. RelationNumaNode, /// /// The specified logical processors share a cache. /// /// Windows Server 2003: This value is not supported until Windows Server 2003 with SP1 and Windows XP Professional x64 Edition. /// /// RelationCache, /// /// /// The specified logical processors share a physical package (a single package socketed or soldered onto a motherboard may /// contain multiple processor cores or threads, each of which is treated as a separate processor by the operating system). /// /// /// Windows Server 2003: This value is not supported until Windows Server 2003 with SP1 and Windows XP Professional x64 Edition. /// /// RelationProcessorPackage, /// /// The specified logical processors share a single processor group. /// /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP Professional x64 Edition: This value is not /// supported until Windows Server 2008 R2. /// /// RelationGroup, /// /// On input, retrieves information about all possible relationship types. This value is not used on output. /// /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP Professional x64 Edition: This value is not /// supported until Windows Server 2008 R2. /// /// RelationAll = 0xffff, } /// Represents the type of processor cache identified in the corresponding CACHE_DESCRIPTOR structure. // typedef enum _PROCESSOR_CACHE_TYPE { CacheUnified, CacheInstruction, CacheData, CacheTrace} PROCESSOR_CACHE_TYPE; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684844(v=vs.85).aspx [PInvokeData("WinNT.h", MSDNShortId = "ms684844")] public enum PROCESSOR_CACHE_TYPE { /// The cache is unified. CacheUnified, /// The cache is for processor instructions. CacheInstruction, /// The cache is for data. CacheData, /// The cache is for traces. CacheTrace, } /// The product type. [PInvokeData("Winbase.h")] public enum PRODUCT_TYPE : uint { /// Business PRODUCT_BUSINESS = 0x00000006, /// Business N PRODUCT_BUSINESS_N = 0x00000010, /// HPC Edition PRODUCT_CLUSTER_SERVER = 0x00000012, /// Server Hyper Core V PRODUCT_CLUSTER_SERVER_V = 0x00000040, /// Windows 10 Home PRODUCT_CORE = 0x00000065, /// Windows 10 Home China PRODUCT_CORE_COUNTRYSPECIFIC = 0x00000063, /// Windows 10 Home N PRODUCT_CORE_N = 0x00000062, /// Windows 10 Home Single Language PRODUCT_CORE_SINGLELANGUAGE = 0x00000064, /// Server Datacenter (evaluation installation) PRODUCT_DATACENTER_EVALUATION_SERVER = 0x00000050, /// Server Datacenter (full installation) PRODUCT_DATACENTER_SERVER = 0x00000008, /// Server Datacenter (core installation) PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C, /// Server Datacenter without Hyper-V (core installation) PRODUCT_DATACENTER_SERVER_CORE_V = 0x00000027, /// Server Datacenter without Hyper-V (full installation) PRODUCT_DATACENTER_SERVER_V = 0x00000025, /// Windows 10 Education PRODUCT_EDUCATION = 0x00000079, /// Windows 10 Education N PRODUCT_EDUCATION_N = 0x0000007A, /// Windows 10 Enterprise PRODUCT_ENTERPRISE = 0x00000004, /// Windows 10 Enterprise E PRODUCT_ENTERPRISE_E = 0x00000046, /// Windows 10 Enterprise Evaluation PRODUCT_ENTERPRISE_EVALUATION = 0x00000048, /// Windows 10 Enterprise N PRODUCT_ENTERPRISE_N = 0x0000001B, /// Windows 10 Enterprise N Evaluation PRODUCT_ENTERPRISE_N_EVALUATION = 0x00000054, /// Windows 10 Enterprise 2015 LTSB PRODUCT_ENTERPRISE_S = 0x0000007D, /// Windows 10 Enterprise 2015 LTSB Evaluation PRODUCT_ENTERPRISE_S_EVALUATION = 0x00000081, /// Windows 10 Enterprise 2015 LTSB N PRODUCT_ENTERPRISE_S_N = 0x0000007E, /// Windows 10 Enterprise 2015 LTSB N Evaluation PRODUCT_ENTERPRISE_S_N_EVALUATION = 0x00000082, /// Server Enterprise (full installation) PRODUCT_ENTERPRISE_SERVER = 0x0000000A, /// Server Enterprise (core installation) PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E, /// Server Enterprise without Hyper-V (core installation) PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029, /// Server Enterprise for Itanium-based Systems PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F, /// Server Enterprise without Hyper-V (full installation) PRODUCT_ENTERPRISE_SERVER_V = 0x00000026, /// Windows Essential Server Solution Additional PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL = 0x0000003C, /// Windows Essential Server Solution Additional SVC PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC = 0x0000003E, /// Windows Essential Server Solution Management PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT = 0x0000003B, /// Windows Essential Server Solution Management SVC PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC = 0x0000003D, /// Home Basic PRODUCT_HOME_BASIC = 0x00000002, /// Not supported PRODUCT_HOME_BASIC_E = 0x00000043, /// Home Basic N PRODUCT_HOME_BASIC_N = 0x00000005, /// Home Premium PRODUCT_HOME_PREMIUM = 0x00000003, /// Not supported PRODUCT_HOME_PREMIUM_E = 0x00000044, /// Home Premium N PRODUCT_HOME_PREMIUM_N = 0x0000001A, /// Windows Home Server 2011 PRODUCT_HOME_PREMIUM_SERVER = 0x00000022, /// Windows Storage Server 2008 R2 Essentials PRODUCT_HOME_SERVER = 0x00000013, /// PRODUCT_HYPERV = 0x0000002A, /// Windows 10 IoT Core PRODUCT_IOTUAP = 0x0000007B, /// Windows 10 IoT Core Commercial PRODUCT_IOTUAPCOMMERCIAL = 0x00000083, /// Windows Essential Business Server Management Server PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E, /// Windows Essential Business Server Messaging Server PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020, /// Windows Essential Business Server Security Server PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F, /// Windows 10 Mobile PRODUCT_MOBILE_CORE = 0x00000068, /// Windows 10 Mobile Enterprise PRODUCT_MOBILE_ENTERPRISE = 0x00000085, /// Windows MultiPoint Server Premium (full installation) PRODUCT_MULTIPOINT_PREMIUM_SERVER = 0x0000004D, /// Windows MultiPoint Server Standard (full installation) PRODUCT_MULTIPOINT_STANDARD_SERVER = 0x0000004C, /// Windows 10 Pro for Workstations PRODUCT_PRO_WORKSTATION = 0x000000A1, /// Windows 10 Pro for Workstations N PRODUCT_PRO_WORKSTATION_N = 0x000000A2, /// Windows 10 Pro PRODUCT_PROFESSIONAL = 0x00000030, /// Not supported PRODUCT_PROFESSIONAL_E = 0x00000045, /// Windows 10 Pro N PRODUCT_PROFESSIONAL_N = 0x00000031, /// Professional with Media Center PRODUCT_PROFESSIONAL_WMC = 0x00000067, /// Windows Small Business Server 2011 Essentials PRODUCT_SB_SOLUTION_SERVER = 0x00000032, /// Server For SB Solutions EM PRODUCT_SB_SOLUTION_SERVER_EM = 0x00000036, /// Server For SB Solutions PRODUCT_SERVER_FOR_SB_SOLUTIONS = 0x00000033, /// Server For SB Solutions EM PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM = 0x00000037, /// Windows Server 2008 for Windows Essential Server Solutions PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018, /// Windows Server 2008 without Hyper-V for Windows Essential Server Solutions PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023, /// Server Foundation PRODUCT_SERVER_FOUNDATION = 0x00000021, /// Windows Small Business Server PRODUCT_SMALLBUSINESS_SERVER = 0x00000009, /// Small Business Server Premium PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = 0x00000019, /// Small Business Server Premium (core installation) PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE = 0x0000003F, /// Windows MultiPoint Server PRODUCT_SOLUTION_EMBEDDEDSERVER = 0x00000038, /// Server Standard (evaluation installation) PRODUCT_STANDARD_EVALUATION_SERVER = 0x0000004F, /// Server Standard PRODUCT_STANDARD_SERVER = 0x00000007, /// Server Standard (core installation) PRODUCT_STANDARD_SERVER_CORE = 0x0000000D, /// Server Standard without Hyper-V (core installation) PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028, /// Server Standard without Hyper-V PRODUCT_STANDARD_SERVER_V = 0x00000024, /// Server Solutions Premium PRODUCT_STANDARD_SERVER_SOLUTIONS = 0x00000034, /// Server Solutions Premium (core installation) PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE = 0x00000035, /// Starter PRODUCT_STARTER = 0x0000000B, /// Not supported PRODUCT_STARTER_E = 0x00000042, /// Starter N PRODUCT_STARTER_N = 0x0000002F, /// Storage Server Enterprise PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017, /// Storage Server Enterprise (core installation) PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE = 0x0000002E, /// Storage Server Express PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014, /// Storage Server Express (core installation) PRODUCT_STORAGE_EXPRESS_SERVER_CORE = 0x0000002B, /// Storage Server Standard (evaluation installation) PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER = 0x00000060, /// Storage Server Standard PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015, /// Storage Server Standard (core installation) PRODUCT_STORAGE_STANDARD_SERVER_CORE = 0x0000002C, /// Storage Server Workgroup (evaluation installation) PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER = 0x0000005F, /// Storage Server Workgroup PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016, /// Storage Server Workgroup (core installation) PRODUCT_STORAGE_WORKGROUP_SERVER_CORE = 0x0000002D, /// Ultimate PRODUCT_ULTIMATE = 0x00000001, /// Not supported PRODUCT_ULTIMATE_E = 0x00000047, /// Ultimate N PRODUCT_ULTIMATE_N = 0x0000001C, /// An unknown product PRODUCT_UNDEFINED = 0x00000000, /// Web Server (full installation) PRODUCT_WEB_SERVER = 0x00000011, /// Web Server (core installation) PRODUCT_WEB_SERVER_CORE = 0x0000001D, } /// Any additional information about the system. [PInvokeData("Winnt.h", MSDNShortId = "ms724833")] public enum ProductType : byte { /// /// The system is a domain controller and the operating system is Windows Server 2012 , Windows Server 2008 R2, Windows Server /// 2008, Windows Server 2003, or Windows 2000 Server. /// VER_NT_DOMAIN_CONTROLLER = 0x0000002, /// /// The operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows /// 2000 Server. /// Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER. /// VER_NT_SERVER = 0x0000003, /// /// The operating system is Windows 8, Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows /// 2000 Professional. /// VER_NT_WORKSTATION = 0x0000001, } /// Flags for SetComputerNameEx2. public enum SCEX2 { /// Undocumented. SCEX2_ALT_NETBIOS_NAME = 0x00000001, } /// A bit mask that identifies the product suites available on the system. [PInvokeData("Winnt.h", MSDNShortId = "ms724833")] [Flags] public enum SuiteMask : ushort { /// Microsoft BackOffice components are installed. VER_SUITE_BACKOFFICE = 0x00000004, /// Windows Server 2003, Web Edition is installed. VER_SUITE_BLADE = 0x00000400, /// Windows Server 2003, Compute Cluster Edition is installed. VER_SUITE_COMPUTE_SERVER = 0x00004000, /// /// Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed. /// VER_SUITE_DATACENTER = 0x00000080, /// /// Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer /// to the Remarks section for more information about this bit flag. /// VER_SUITE_ENTERPRISE = 0x00000002, /// Windows XP Embedded is installed. VER_SUITE_EMBEDDEDNT = 0x00000040, /// Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed. VER_SUITE_PERSONAL = 0x00000200, /// /// Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in /// application server mode. /// VER_SUITE_SINGLEUSERTS = 0x00000100, /// /// Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. /// Refer to the Remarks section for more information about this bit flag. /// VER_SUITE_SMALLBUSINESS = 0x00000001, /// /// Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for /// more information about this bit flag. /// VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020, /// Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed. VER_SUITE_STORAGE_SERVER = 0x00002000, /// /// Terminal Services is installed. This value is always set. /// If VER_SUITE_TERMINAL is set but VER_SUITE_SINGLEUSERTS is not set, the system is running in application server mode. /// VER_SUITE_TERMINAL = 0x00000010, /// Windows Home Server is installed. VER_SUITE_WH_SERVER = 0x00008000, } /// Converts a DNS-style host name to a NetBIOS-style computer name. /// /// The DNS name. If the DNS name is not a valid, translatable name, the function fails. For more information, see Computer Names. /// /// /// A pointer to a buffer that receives the computer name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH /// + 1 characters. /// /// /// /// On input, specifies the size of the buffer, in TCHARs. On output, receives the number of TCHARs copied to the /// destination buffer, not including the terminating null character. /// /// /// If the buffer is too small, the function fails, GetLastError returns ERROR_MORE_DATA, and nSize receives the required buffer /// size, not including the terminating null character. /// /// /// /// If the function succeeds, the return value is a nonzero value. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible values include /// the following. /// /// /// /// Return code /// Description /// /// /// ERROR_MORE_DATA /// The ComputerName buffer is too small. The nSize parameter contains the number of bytes required to receive the name. /// /// /// /// /// /// This function performs a textual mapping of the name. This convention limits the names of computers to be the common subset of /// the names. (Specifically, the leftmost label of the DNS name is truncated to 15-bytes of OEM characters.) Therefore, do not use /// this function to convert a DNS domain name to a NetBIOS domain name. There is no textual mapping for domain names. /// /// /// To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the /// Windows Headers. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-dnshostnametocomputernamea BOOL DnsHostnameToComputerNameA( // LPCSTR Hostname, LPSTR ComputerName, LPDWORD nSize ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "d5646fe6-9112-42cd-ace9-00dd1b590ecb")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DnsHostnameToComputerName(string Hostname, StringBuilder ComputerName, ref uint nSize); /// Converts a DNS-style host name to a NetBIOS-style computer name. /// /// The DNS name. If the DNS name is not a valid, translatable name, the function fails. For more information, see Computer Names. /// /// Receives the computer name. /// /// If the function succeeds, the return value is a nonzero value. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible values include /// the following. /// /// /// /// Return code /// Description /// /// /// ERROR_MORE_DATA /// The ComputerName buffer is too small. The nSize parameter contains the number of bytes required to receive the name. /// /// /// /// /// /// This function performs a textual mapping of the name. This convention limits the names of computers to be the common subset of /// the names. (Specifically, the leftmost label of the DNS name is truncated to 15-bytes of OEM characters.) Therefore, do not use /// this function to convert a DNS domain name to a NetBIOS domain name. There is no textual mapping for domain names. /// /// public static bool DnsHostnameToComputerName(string Hostname, out string ComputerName) => CallMethodWithStrBuf((StringBuilder sb, ref uint sz) => DnsHostnameToComputerName(Hostname, sb, ref sz), out ComputerName); /// Enumerates all system firmware tables of the specified type. /// /// /// The identifier of the firmware table provider to which the query is to be directed. This parameter can be one of the following values. /// /// /// /// /// Value /// Meaning /// /// /// 'ACPI' /// The ACPI firmware table provider. /// /// /// 'FIRM' /// The raw firmware table provider. Not supported for UEFI systems; use 'RSMB' instead. /// /// /// 'RSMB' /// The raw SMBIOS firmware table provider. /// /// /// /// /// /// /// A pointer to a buffer that receives the list of firmware tables. If this parameter is NULL, the return value is the /// required buffer size. /// /// For more information on the contents of this buffer, see the Remarks section. /// /// The size of the pFirmwareTableBuffer buffer, in bytes. /// /// /// If the function succeeds, the return value is the number of bytes written to the buffer. This value will always be less than or /// equal to BufferSize. /// /// /// If the function fails because the buffer is not large enough, the return value is the required buffer size, in bytes. This value /// is always greater than BufferSize. /// /// If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError. /// // UINT WINAPI EnumSystemFirmwareTables( _In_ DWORD FirmwareTableProviderSignature, _Out_ PVOID pFirmwareTableBuffer, _In_ DWORD // BufferSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724259(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724259")] public static extern uint EnumSystemFirmwareTables(FirmwareTableProviderId FirmwareTableProviderSignature, IntPtr pFirmwareTableBuffer, uint BufferSize); /// Enumerates all system firmware tables of the specified type. /// /// /// The identifier of the firmware table provider to which the query is to be directed. This parameter can be one of the following values. /// /// /// /// /// Value /// Meaning /// /// /// 'ACPI' /// The ACPI firmware table provider. /// /// /// 'FIRM' /// The raw firmware table provider. Not supported for UEFI systems; use 'RSMB' instead. /// /// /// 'RSMB' /// The raw SMBIOS firmware table provider. /// /// /// /// /// /// A list of firmware tables. /// For more information on the contents of this buffer, see the Remarks section. /// /// /// /// If the function succeeds, the return value is the number of bytes written to the buffer. This value will always be less than or /// equal to BufferSize. /// /// /// If the function fails because the buffer is not large enough, the return value is the required buffer size, in bytes. This value /// is always greater than BufferSize. /// /// If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError. /// public static Win32Error EnumSystemFirmwareTables(FirmwareTableProviderId FirmwareTableProviderSignature, out uint[] tableIdentifiers) { return CallMethodWithTypedBuf( (ref uint sz) => BoolToLastErr((sz = EnumSystemFirmwareTables(FirmwareTableProviderSignature, IntPtr.Zero, 0)) > 0), (IntPtr p, ref uint sz) => BoolToLastErr((sz = EnumSystemFirmwareTables(FirmwareTableProviderSignature, p, sz)) > 0), out tableIdentifiers, (p, sz) => p.ToArray((int)sz / Marshal.SizeOf(typeof(uint)))); } /// /// /// Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry. /// /// /// GetComputerName retrieves only the NetBIOS name of the local computer. To retrieve the DNS host name, DNS domain name, or /// the fully qualified DNS name, call the GetComputerNameEx function. Additional information is provided by the /// IADsADSystemInfo interface. /// /// /// The behavior of this function can be affected if the local computer is a node in a cluster. For more information, see /// ResUtilGetEnvironmentWithNetName and UseNetworkName. /// /// /// /// A pointer to a buffer that receives the computer name or the cluster virtual server name. The buffer size should be large enough /// to contain MAX_COMPUTERNAME_LENGTH + 1 characters. /// /// /// /// On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs copied to the destination /// buffer, not including the terminating null character. /// /// /// If the buffer is too small, the function fails and GetLastError returns ERROR_BUFFER_OVERFLOW. The lpnSize parameter /// specifies the size of the buffer required, including the terminating null character. /// /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI GetComputerName( _Out_ LPTSTR lpBuffer, _Inout_ LPDWORD lpnSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724295")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetComputerName(StringBuilder lpBuffer, ref uint lpnSize); /// /// /// Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry. /// /// /// GetComputerName retrieves only the NetBIOS name of the local computer. To retrieve the DNS host name, DNS domain name, or /// the fully qualified DNS name, call the GetComputerNameEx function. Additional information is provided by the /// IADsADSystemInfo interface. /// /// /// The behavior of this function can be affected if the local computer is a node in a cluster. For more information, see /// ResUtilGetEnvironmentWithNetName and UseNetworkName. /// /// /// The computer name or the cluster virtual server name. /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// public static bool GetComputerName(out string name) => CallMethodWithStrBuf((StringBuilder sb, ref uint sz) => GetComputerName(sb, ref sz), out name); /// /// Retrieves a NetBIOS or DNS name associated with the local computer. The names are established at system startup, when the system /// reads them from the registry. /// /// /// /// The type of name to be retrieved. This parameter is a value from the COMPUTER_NAME_FORMAT enumeration type. The following /// table provides additional information. /// /// /// /// /// Value /// Meaning /// /// /// ComputerNameDnsDomain /// /// The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the /// DNS domain name of the cluster virtual server. /// /// /// /// ComputerNameDnsFullyQualified /// /// The fully qualified DNS name that uniquely identifies the local computer. This name is a combination of the DNS host name and the /// DNS domain name, using the form HostName.DomainName. If the local computer is a node in a cluster, lpBuffer receives the fully /// qualified DNS name of the cluster virtual server. /// /// /// /// ComputerNameDnsHostname /// /// The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the /// cluster virtual server. /// /// /// /// ComputerNameNetBIOS /// /// The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the /// cluster virtual server. /// /// /// /// ComputerNamePhysicalDnsDomain /// /// The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the /// DNS domain name of the local computer, not the name of the cluster virtual server. /// /// /// /// ComputerNamePhysicalDnsFullyQualified /// /// The fully qualified DNS name that uniquely identifies the computer. If the local computer is a node in a cluster, lpBuffer /// receives the fully qualified DNS name of the local computer, not the name of the cluster virtual server. The fully qualified DNS /// name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. /// /// /// /// ComputerNamePhysicalDnsHostname /// /// The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the /// local computer, not the name of the cluster virtual server. /// /// /// /// ComputerNamePhysicalNetBIOS /// /// The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the /// local computer, not the name of the cluster virtual server. /// /// /// /// /// /// /// A pointer to a buffer that receives the computer name or the cluster virtual server name. /// /// The length of the name may be greater than MAX_COMPUTERNAME_LENGTH characters because DNS allows longer names. To ensure that /// this buffer is large enough, set this parameter to NULL and use the required buffer size returned in the lpnSize parameter. /// /// /// /// /// On input, specifies the size of the buffer, in TCHARs. On output, receives the number of TCHARs copied to the /// destination buffer, not including the terminating null character. /// /// /// If the buffer is too small, the function fails and GetLastError returns ERROR_MORE_DATA. This parameter receives the size /// of the buffer required, including the terminating null character. /// /// If lpBuffer is NULL, this parameter must be zero. /// /// /// If the function succeeds, the return value is a nonzero value. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible values /// include the following. /// /// /// /// /// Return code /// Description /// /// /// ERROR_MORE_DATA /// The lpBuffer buffer is too small. The lpnSize parameter contains the number of bytes required to receive the name. /// /// /// /// // BOOL WINAPI GetComputerNameEx( _In_ COMPUTER_NAME_FORMAT NameType, _Out_ LPTSTR lpBuffer, _Inout_ LPDWORD lpnSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724301(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724301")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetComputerNameEx(COMPUTER_NAME_FORMAT NameType, StringBuilder lpBuffer, ref uint lpnSize); /// /// Retrieves a NetBIOS or DNS name associated with the local computer. The names are established at system startup, when the system /// reads them from the registry. /// /// /// /// The type of name to be retrieved. This parameter is a value from the COMPUTER_NAME_FORMAT enumeration type. The following /// table provides additional information. /// /// /// /// /// Value /// Meaning /// /// /// ComputerNameDnsDomain /// /// The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the /// DNS domain name of the cluster virtual server. /// /// /// /// ComputerNameDnsFullyQualified /// /// The fully qualified DNS name that uniquely identifies the local computer. This name is a combination of the DNS host name and the /// DNS domain name, using the form HostName.DomainName. If the local computer is a node in a cluster, lpBuffer receives the fully /// qualified DNS name of the cluster virtual server. /// /// /// /// ComputerNameDnsHostname /// /// The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the /// cluster virtual server. /// /// /// /// ComputerNameNetBIOS /// /// The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the /// cluster virtual server. /// /// /// /// ComputerNamePhysicalDnsDomain /// /// The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the /// DNS domain name of the local computer, not the name of the cluster virtual server. /// /// /// /// ComputerNamePhysicalDnsFullyQualified /// /// The fully qualified DNS name that uniquely identifies the computer. If the local computer is a node in a cluster, lpBuffer /// receives the fully qualified DNS name of the local computer, not the name of the cluster virtual server. The fully qualified DNS /// name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. /// /// /// /// ComputerNamePhysicalDnsHostname /// /// The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the /// local computer, not the name of the cluster virtual server. /// /// /// /// ComputerNamePhysicalNetBIOS /// /// The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the /// local computer, not the name of the cluster virtual server. /// /// /// /// /// /// The computer name or the cluster virtual server name. /// /// If the function succeeds, the return value is a nonzero value. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible values /// include the following. /// /// /// /// /// Return code /// Description /// /// /// ERROR_MORE_DATA /// The lpBuffer buffer is too small. The lpnSize parameter contains the number of bytes required to receive the name. /// /// /// /// public static bool GetComputerNameEx(COMPUTER_NAME_FORMAT NameType, out string name) => CallMethodWithStrBuf((StringBuilder sb, ref uint sz) => GetComputerNameEx(NameType, sb, ref sz), out name); /// Retrieves the value of the specified firmware environment variable. /// The name of the firmware environment variable. The pointer must not be NULL. /// /// The GUID that represents the namespace of the firmware environment variable. The GUID must be a string in the format /// "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' represents a hexadecimal value. /// /// A pointer to a buffer that receives the value of the specified firmware environment variable. /// The size of the pBuffer buffer, in bytes. /// /// If the function succeeds, the return value is the number of bytes stored in the pBuffer buffer. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible error /// codes include ERROR_INVALID_FUNCTION. /// /// // DWORD WINAPI GetFirmwareEnvironmentVariable( _In_ LPCTSTR lpName, _In_ LPCTSTR lpGuid, _Out_ PVOID pBuffer, _In_ DWORD nSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724325(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724325")] public static extern uint GetFirmwareEnvironmentVariable(string lpName, string lpGuid, IntPtr pBuffer, uint nSize); /// /// Retrieves the best estimate of the diagonal size of the built-in screen, in inches. /// /// The best estimate of the diagonal size of the built-in screen, in inches. /// The result code indicating if the function succeeded or failed. // WINAPI GetIntegratedDisplaySize( _Out_ double *sizeInInches); https://msdn.microsoft.com/en-us/library/windows/desktop/dn904185(v=vs.85).aspx [DllImport(Lib.KernelBase, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "dn904185")] public static extern HRESULT GetIntegratedDisplaySize(out double sizeInInches); /// /// Retrieves the current local date and time. /// To retrieve the current date and time in Coordinated Universal Time (UTC) format, use the GetSystemTime function. /// /// A pointer to a SYSTEMTIME structure to receive the current local date and time. /// This function does not return a value. // void WINAPI GetLocalTime( _Out_ LPSYSTEMTIME lpSystemTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724338(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724338")] public static extern void GetLocalTime(out SYSTEMTIME lpSystemTime); /// /// Retrieves information about logical processors and related hardware. /// /// To retrieve information about logical processors and related hardware, including processor groups, use the /// GetLogicalProcessorInformationEx function. /// /// /// /// A pointer to a buffer that receives an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures. If the function fails, /// the contents of this buffer are undefined. /// /// /// On input, specifies the length of the buffer pointed to by Buffer, in bytes. If the buffer is large enough to contain all of the /// data, this function succeeds and ReturnLength is set to the number of bytes returned. If the buffer is not large enough to /// contain all of the data, the function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and ReturnLength is set to /// the buffer length required to contain all of the data. If the function fails with an error other than ERROR_INSUFFICIENT_BUFFER, /// the value of ReturnLength is undefined. /// /// /// /// If the function succeeds, the return value is TRUE and at least one SYSTEM_LOGICAL_PROCESSOR_INFORMATION structure is /// written to the output buffer. /// /// If the function fails, the return value is FALSE. To get extended error information, call GetLastError. /// // BOOL WINAPI GetLogicalProcessorInformation( _Out_ PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer, _Inout_ PDWORD ReturnLength); https://msdn.microsoft.com/en-us/library/windows/desktop/ms683194(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "ms683194")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetLogicalProcessorInformation(IntPtr Buffer, ref uint ReturnLength); /// /// Retrieves information about logical processors and related hardware. /// /// To retrieve information about logical processors and related hardware, including processor groups, use the /// GetLogicalProcessorInformationEx function. /// /// /// /// An array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures. If the function fails, the contents of this buffer are undefined. /// /// /// /// If the function succeeds, the return value is ERROR_SUCCESS and at least one SYSTEM_LOGICAL_PROCESSOR_INFORMATION /// structure is written to the output buffer. /// /// If the function fails, the return value has error information. /// public static Win32Error GetLogicalProcessorInformation(out SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] info) { return CallMethodWithTypedBuf( (ref uint sz) => BoolToLastErr(GetLogicalProcessorInformation(IntPtr.Zero, ref sz) || sz > 0), (IntPtr p, ref uint sz) => BoolToLastErr(GetLogicalProcessorInformation(p, ref sz)), out info, (p, sz) => p.ToArray((int)sz / Marshal.SizeOf(typeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION)))); } /// Retrieves information about the relationships of logical processors and related hardware. /// /// /// The type of relationship to retrieve. This parameter can be one of the following LOGICAL_PROCESSOR_RELATIONSHIP values. /// /// /// /// /// Value /// Meaning /// /// /// RelationCache2 /// Retrieves information about logical processors that share a cache. /// /// /// RelationNumaNode1 /// Retrieves information about logical processors that are part of the same NUMA node. /// /// /// RelationProcessorCore0 /// Retrieves information about logical processors that share a single processor core. /// /// /// RelationProcessorPackage3 /// Retrieves information about logical processors that share a physical package. /// /// /// RelationGroup4 /// Retrieves information about logical processors that share a processor group. /// /// /// RelationAll0xffff /// /// Retrieves information about logical processors for all relationship types (cache, NUMA node, processor core, physical package, /// and processor group). /// /// /// /// /// /// /// A pointer to a buffer that receives an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structures. If the function fails, /// the contents of this buffer are undefined. /// /// /// On input, specifies the length of the buffer pointed to by Buffer, in bytes. If the buffer is large enough to contain all of the /// data, this function succeeds and ReturnedLength is set to the number of bytes returned. If the buffer is not large enough to /// contain all of the data, the function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and ReturnedLength is set to /// the buffer length required to contain all of the data. If the function fails with an error other than ERROR_INSUFFICIENT_BUFFER, /// the value of ReturnedLength is undefined. /// /// /// /// If the function succeeds, the return value is TRUE and at least one SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is /// written to the output buffer. /// /// If the function fails, the return value is FALSE. To get extended error information, call GetLastError. /// // BOOL GetLogicalProcessorInformationEx( _In_ LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, _Out_opt_ // PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Buffer, _Inout_ PDWORD ReturnedLength); https://msdn.microsoft.com/en-us/library/windows/desktop/dd405488(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "dd405488")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, IntPtr Buffer, ref uint ReturnedLength); /// Retrieves information about the relationships of logical processors and related hardware. /// /// /// The type of relationship to retrieve. This parameter can be one of the following LOGICAL_PROCESSOR_RELATIONSHIP values. /// /// /// /// /// Value /// Meaning /// /// /// RelationCache2 /// Retrieves information about logical processors that share a cache. /// /// /// RelationNumaNode1 /// Retrieves information about logical processors that are part of the same NUMA node. /// /// /// RelationProcessorCore0 /// Retrieves information about logical processors that share a single processor core. /// /// /// RelationProcessorPackage3 /// Retrieves information about logical processors that share a physical package. /// /// /// RelationGroup4 /// Retrieves information about logical processors that share a processor group. /// /// /// RelationAll0xffff /// /// Retrieves information about logical processors for all relationship types (cache, NUMA node, processor core, physical package, /// and processor group). /// /// /// /// /// /// /// An array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structures. If the function fails, the contents of this buffer are undefined. /// /// /// /// If the function succeeds, the return value is ERROR_SUCCESS and at least one SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX /// structure is written to the output buffer. /// /// If the function fails, the return value has error information. /// public static Win32Error GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, out SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[] info) { return CallMethodWithTypedBuf( (ref uint sz) => BoolToLastErr(GetLogicalProcessorInformationEx(RelationshipType, IntPtr.Zero, ref sz) || sz > 0), (IntPtr p, ref uint sz) => BoolToLastErr(GetLogicalProcessorInformationEx(RelationshipType, p, ref sz)), out info, (p, sz) => p.ToArray((int)sz / Marshal.SizeOf(typeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)))); } /// /// Retrieves information about the current system to an application running under WOW64. If the function is called from a 64-bit /// application, it is equivalent to the GetSystemInfo function. /// /// A pointer to a SYSTEM_INFO structure that receives the information. /// This function does not return a value. // void WINAPI GetNativeSystemInfo( _Out_ LPSYSTEM_INFO lpSystemInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724340(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724340")] public static extern void GetNativeSystemInfo(out SYSTEM_INFO lpSystemInfo); /// Determine whether the device is in Manufacturing Mode or not. /// if set to true the device is in Manufacturing Mode. /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetOsManufacturingMode([MarshalAs(UnmanagedType.Bool)] out bool pbEnabled); /// Undocumented. /// Undocumented flags. /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetOsSafeBootMode(out uint Flags); /// Retrieves the amount of RAM that is physically installed on the computer. /// A pointer to a variable that receives the amount of physically installed RAM, in kilobytes. /// /// If the function succeeds, it returns TRUE and sets the TotalMemoryInKilobytes parameter to a nonzero value. /// /// If the function fails, it returns FALSE and does not modify the TotalMemoryInKilobytes parameter. To get extended error /// information, use the GetLastError function. Common errors are listed in the following table. /// /// /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// The TotalMemoryInKilobytes parameter is NULL. /// /// /// ERROR_INVALID_DATA /// The System Management BIOS (SMBIOS) data is malformed. /// /// /// /// // BOOL WINAPI GetPhysicallyInstalledSystemMemory( _Out_ PULONGLONG TotalMemoryInKilobytes); https://msdn.microsoft.com/en-us/library/windows/desktop/cc300158(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "cc300158")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetPhysicallyInstalledSystemMemory(out ulong TotalMemoryInKilobytes); /// /// Retrieves the cycle time each processor in the specified processor group spent executing deferred procedure calls (DPCs) and /// interrupt service routines (ISRs) since the processor became active. /// /// The number of the processor group for which to retrieve the cycle time. /// /// A pointer to a buffer to receive a SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION structure for each processor in the group. On output, /// the DWORD64 CycleTime member of this structure is set to the cycle time for one processor. /// /// /// The size of the buffer, in bytes. When the function returns, this parameter contains the number of bytes written to Buffer. If /// the buffer is too small for the data, the function fails with ERROR_INSUFFICIENT_BUFFER and sets the ReturnedLength parameter to /// the required buffer size. /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, use GetLastError. /// If the error value is ERROR_INSUFFICIENT_BUFFER, the ReturnedLength parameter contains the required buffer size. /// // BOOL GetProcessorSystemCycleTime( _In_ USHORT Group, _Out_ PSYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION Buffer, _Inout_ PDWORD // ReturnedLength); https://msdn.microsoft.com/en-us/library/windows/desktop/dd405497(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "dd405497")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetProcessorSystemCycleTime(ushort Group, IntPtr Buffer, ref uint ReturnedLength); /// /// Retrieves the cycle time each processor in the specified processor group spent executing deferred procedure calls (DPCs) and /// interrupt service routines (ISRs) since the processor became active. /// /// The number of the processor group for which to retrieve the cycle time. /// /// A SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION structure for each processor in the group. On output, the DWORD64 CycleTime /// member of this structure is set to the cycle time for one processor. /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, use GetLastError. /// If the error value is ERROR_INSUFFICIENT_BUFFER, the ReturnedLength parameter contains the required buffer size. /// public static Win32Error GetProcessorSystemCycleTime(ushort Group, out SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION[] cycleTimes) { return CallMethodWithTypedBuf( (ref uint sz) => BoolToLastErr(GetProcessorSystemCycleTime(Group, IntPtr.Zero, ref sz) || sz > 0), (IntPtr p, ref uint sz) => BoolToLastErr(GetProcessorSystemCycleTime(Group, p, ref sz)), out cycleTimes, (p, sz) => p.ToArray((int)sz / Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION)))); } /// /// /// Retrieves the product type for the operating system on the local computer, and maps the type to the product types supported by /// the specified operating system. /// /// /// To retrieve product type information on versions of Windows prior to the minimum supported operating systems specified in the /// Requirements section, use the GetVersionEx function. You can also use the OperatingSystemSKU property of the /// Win32_OperatingSystem WMI class. /// /// /// /// The major version number of the operating system. The minimum value is 6. /// /// The combination of the dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, and dwSpMinorVersion parameters describes the /// maximum target operating system version for the application. For example, Windows Vista and Windows Server 2008 are version /// 6.0.0.0 and Windows 7 and Windows Server 2008 R2 are version 6.1.0.0. /// /// /// The minor version number of the operating system. The minimum value is 0. /// The major version number of the operating system service pack. The minimum value is 0. /// The minor version number of the operating system service pack. The minimum value is 0. /// /// /// The product type. This parameter cannot be NULL. If the specified operating system is less than the current operating /// system, this information is mapped to the types supported by the specified operating system. If the specified operating system is /// greater than the highest supported operating system, this information is mapped to the types supported by the current operating system. /// /// This parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// PRODUCT_BUSINESS0x00000006 /// Business /// /// /// PRODUCT_BUSINESS_N0x00000010 /// Business N /// /// /// PRODUCT_CLUSTER_SERVER0x00000012 /// HPC Edition /// /// /// PRODUCT_CLUSTER_SERVER_V0x00000040 /// Server Hyper Core V /// /// /// PRODUCT_CORE0x00000065 /// Windows 10 Home /// /// /// PRODUCT_CORE_COUNTRYSPECIFIC0x00000063 /// Windows 10 Home China /// /// /// PRODUCT_CORE_N0x00000062 /// Windows 10 Home N /// /// /// PRODUCT_CORE_SINGLELANGUAGE0x00000064 /// Windows 10 Home Single Language /// /// /// PRODUCT_DATACENTER_EVALUATION_SERVER0x00000050 /// Server Datacenter (evaluation installation) /// /// /// PRODUCT_DATACENTER_SERVER0x00000008 /// Server Datacenter (full installation) /// /// /// PRODUCT_DATACENTER_SERVER_CORE0x0000000C /// Server Datacenter (core installation) /// /// /// PRODUCT_DATACENTER_SERVER_CORE_V0x00000027 /// Server Datacenter without Hyper-V (core installation) /// /// /// PRODUCT_DATACENTER_SERVER_V0x00000025 /// Server Datacenter without Hyper-V (full installation) /// /// /// PRODUCT_EDUCATION0x00000079 /// Windows 10 Education /// /// /// PRODUCT_EDUCATION_N0x0000007A /// Windows 10 Education N /// /// /// PRODUCT_ENTERPRISE0x00000004 /// Windows 10 Enterprise /// /// /// PRODUCT_ENTERPRISE_E0x00000046 /// Windows 10 Enterprise E /// /// /// PRODUCT_ENTERPRISE_EVALUATION0x00000048 /// Windows 10 Enterprise Evaluation /// /// /// PRODUCT_ENTERPRISE_N0x0000001B /// Windows 10 Enterprise N /// /// /// PRODUCT_ENTERPRISE_N_EVALUATION0x00000054 /// Windows 10 Enterprise N Evaluation /// /// /// PRODUCT_ENTERPRISE_S0x0000007D /// Windows 10 Enterprise 2015 LTSB /// /// /// PRODUCT_ENTERPRISE_S_EVALUATION0x00000081 /// Windows 10 Enterprise 2015 LTSB Evaluation /// /// /// PRODUCT_ENTERPRISE_S_N0x0000007E /// Windows 10 Enterprise 2015 LTSB N /// /// /// PRODUCT_ENTERPRISE_S_N_EVALUATION0x00000082 /// Windows 10 Enterprise 2015 LTSB N Evaluation /// /// /// PRODUCT_ENTERPRISE_SERVER0x0000000A /// Server Enterprise (full installation) /// /// /// PRODUCT_ENTERPRISE_SERVER_CORE0x0000000E /// Server Enterprise (core installation) /// /// /// PRODUCT_ENTERPRISE_SERVER_CORE_V0x00000029 /// Server Enterprise without Hyper-V (core installation) /// /// /// PRODUCT_ENTERPRISE_SERVER_IA640x0000000F /// Server Enterprise for Itanium-based Systems /// /// /// PRODUCT_ENTERPRISE_SERVER_V0x00000026 /// Server Enterprise without Hyper-V (full installation) /// /// /// PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL0x0000003C /// Windows Essential Server Solution Additional /// /// /// PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC0x0000003E /// Windows Essential Server Solution Additional SVC /// /// /// PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT0x0000003B /// Windows Essential Server Solution Management /// /// /// PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC0x0000003D /// Windows Essential Server Solution Management SVC /// /// /// PRODUCT_HOME_BASIC0x00000002 /// Home Basic /// /// /// PRODUCT_HOME_BASIC_E0x00000043 /// Not supported /// /// /// PRODUCT_HOME_BASIC_N0x00000005 /// Home Basic N /// /// /// PRODUCT_HOME_PREMIUM0x00000003 /// Home Premium /// /// /// PRODUCT_HOME_PREMIUM_E0x00000044 /// Not supported /// /// /// PRODUCT_HOME_PREMIUM_N0x0000001A /// Home Premium N /// /// /// PRODUCT_HOME_PREMIUM_SERVER0x00000022 /// Windows Home Server 2011 /// /// /// PRODUCT_HOME_SERVER0x00000013 /// Windows Storage Server 2008 R2 Essentials /// /// /// PRODUCT_HYPERV0x0000002A /// Microsoft Hyper-V Server /// /// /// PRODUCT_IOTUAP0x0000007B /// Windows 10 IoT Core /// /// /// PRODUCT_IOTUAPCOMMERCIAL0x00000083 /// Windows 10 IoT Core Commercial /// /// /// PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT0x0000001E /// Windows Essential Business Server Management Server /// /// /// PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING0x00000020 /// Windows Essential Business Server Messaging Server /// /// /// PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY0x0000001F /// Windows Essential Business Server Security Server /// /// /// PRODUCT_MOBILE_CORE0x00000068 /// Windows 10 Mobile /// /// /// PRODUCT_MOBILE_ENTERPRISE0x00000085 /// Windows 10 Mobile Enterprise /// /// /// PRODUCT_MULTIPOINT_PREMIUM_SERVER0x0000004D /// Windows MultiPoint Server Premium (full installation) /// /// /// PRODUCT_MULTIPOINT_STANDARD_SERVER0x0000004C /// Windows MultiPoint Server Standard (full installation) /// /// /// PRODUCT_PRO_WORKSTATION0x000000A1 /// Windows 10 Pro for Workstations /// /// /// PRODUCT_PRO_WORKSTATION_N0x000000A2 /// Windows 10 Pro for Workstations N /// /// /// PRODUCT_PROFESSIONAL0x00000030 /// Windows 10 Pro /// /// /// PRODUCT_PROFESSIONAL_E0x00000045 /// Not supported /// /// /// PRODUCT_PROFESSIONAL_N0x00000031 /// Windows 10 Pro N /// /// /// PRODUCT_PROFESSIONAL_WMC0x00000067 /// Professional with Media Center /// /// /// PRODUCT_SB_SOLUTION_SERVER0x00000032 /// Windows Small Business Server 2011 Essentials /// /// /// PRODUCT_SB_SOLUTION_SERVER_EM0x00000036 /// Server For SB Solutions EM /// /// /// PRODUCT_SERVER_FOR_SB_SOLUTIONS0x00000033 /// Server For SB Solutions /// /// /// PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM0x00000037 /// Server For SB Solutions EM /// /// /// PRODUCT_SERVER_FOR_SMALLBUSINESS0x00000018 /// Windows Server 2008 for Windows Essential Server Solutions /// /// /// PRODUCT_SERVER_FOR_SMALLBUSINESS_V0x00000023 /// Windows Server 2008 without Hyper-V for Windows Essential Server Solutions /// /// /// PRODUCT_SERVER_FOUNDATION0x00000021 /// Server Foundation /// /// /// PRODUCT_SMALLBUSINESS_SERVER0x00000009 /// Windows Small Business Server /// /// /// PRODUCT_SMALLBUSINESS_SERVER_PREMIUM0x00000019 /// Small Business Server Premium /// /// /// PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE0x0000003F /// Small Business Server Premium (core installation) /// /// /// PRODUCT_SOLUTION_EMBEDDEDSERVER0x00000038 /// Windows MultiPoint Server /// /// /// PRODUCT_STANDARD_EVALUATION_SERVER0x0000004F /// Server Standard (evaluation installation) /// /// /// PRODUCT_STANDARD_SERVER0x00000007 /// Server Standard /// /// /// PRODUCT_STANDARD_SERVER_CORE 0x0000000D /// Server Standard (core installation) /// /// /// PRODUCT_STANDARD_SERVER_CORE_V0x00000028 /// Server Standard without Hyper-V (core installation) /// /// /// PRODUCT_STANDARD_SERVER_V0x00000024 /// Server Standard without Hyper-V /// /// /// PRODUCT_STANDARD_SERVER_SOLUTIONS0x00000034 /// Server Solutions Premium /// /// /// PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE0x00000035 /// Server Solutions Premium (core installation) /// /// /// PRODUCT_STARTER0x0000000B /// Starter /// /// /// PRODUCT_STARTER_E0x00000042 /// Not supported /// /// /// PRODUCT_STARTER_N0x0000002F /// Starter N /// /// /// PRODUCT_STORAGE_ENTERPRISE_SERVER0x00000017 /// Storage Server Enterprise /// /// /// PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE0x0000002E /// Storage Server Enterprise (core installation) /// /// /// PRODUCT_STORAGE_EXPRESS_SERVER0x00000014 /// Storage Server Express /// /// /// PRODUCT_STORAGE_EXPRESS_SERVER_CORE0x0000002B /// Storage Server Express (core installation) /// /// /// PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER0x00000060 /// Storage Server Standard (evaluation installation) /// /// /// PRODUCT_STORAGE_STANDARD_SERVER0x00000015 /// Storage Server Standard /// /// /// PRODUCT_STORAGE_STANDARD_SERVER_CORE0x0000002C /// Storage Server Standard (core installation) /// /// /// PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER0x0000005F /// Storage Server Workgroup (evaluation installation) /// /// /// PRODUCT_STORAGE_WORKGROUP_SERVER0x00000016 /// Storage Server Workgroup /// /// /// PRODUCT_STORAGE_WORKGROUP_SERVER_CORE0x0000002D /// Storage Server Workgroup (core installation) /// /// /// PRODUCT_ULTIMATE0x00000001 /// Ultimate /// /// /// PRODUCT_ULTIMATE_E0x00000047 /// Not supported /// /// /// PRODUCT_ULTIMATE_N0x0000001C /// Ultimate N /// /// /// PRODUCT_UNDEFINED0x00000000 /// An unknown product /// /// /// PRODUCT_WEB_SERVER0x00000011 /// Web Server (full installation) /// /// /// PRODUCT_WEB_SERVER_CORE0x0000001D /// Web Server (core installation) /// /// /// /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. This function fails if one of the input parameters is invalid. /// // BOOL WINAPI GetProductInfo( _In_ DWORD dwOSMajorVersion, _In_ DWORD dwOSMinorVersion, _In_ DWORD dwSpMajorVersion, _In_ DWORD // dwSpMinorVersion, _Out_ PDWORD pdwReturnedProductType); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724358(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724358")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetProductInfo(uint dwOSMajorVersion, uint dwOSMinorVersion, uint dwSpMajorVersion, uint dwSpMinorVersion, out PRODUCT_TYPE pdwReturnedProductType); /// /// /// Retrieves the path of the system directory. The system directory contains system files such as dynamic-link libraries and drivers. /// /// /// This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent /// data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath. /// /// /// /// A pointer to the buffer to receive the path. This path does not end with a backslash unless the system directory is the root /// directory. For example, if the system directory is named Windows\System32 on drive C, the path of the system directory retrieved /// by this function is C:\Windows\System32. /// /// The maximum size of the buffer, in TCHARs. /// /// /// If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the /// terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer /// required to hold the path, including the terminating null character. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // UINT WINAPI GetSystemDirectory( _Out_ LPTSTR lpBuffer, _In_ UINT uSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724373(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724373")] public static extern uint GetSystemDirectory(StringBuilder lpBuffer, uint uSize); /// /// /// Retrieves the path of the system directory. The system directory contains system files such as dynamic-link libraries and drivers. /// /// /// This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent /// data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath. /// /// /// /// Receives the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the /// system directory is named Windows\System32 on drive C, the path of the system directory retrieved by this function is C:\Windows\System32. /// public static string GetSystemDirectory() => CallMethodWithStrBuf((sb, sz) => GetSystemDirectory(sb, sz), (uint)MAX_PATH, out var sysDir) != 0 ? sysDir : throw Win32Error.GetLastError().GetException(); /// Retrieves the specified firmware table from the firmware table provider. /// /// /// The identifier of the firmware table provider to which the query is to be directed. This parameter can be one of the following values. /// /// /// /// /// Value /// Meaning /// /// /// 'ACPI' /// The ACPI firmware table provider. /// /// /// 'FIRM' /// The raw firmware table provider. /// /// /// 'RSMB' /// The raw SMBIOS firmware table provider. /// /// /// /// /// /// The identifier of the firmware table. This identifier is little endian, you must reverse the characters in the string. /// /// For example, FACP is an ACPI provider, as described in the Signature field of the DESCRIPTION_HEADER structure in the ACPI /// specification (see http://www.acpi.info). Therefore, use 'PCAF' to specify the FACP table, as shown in the following example: /// /// For more information, see the Remarks section of the EnumSystemFirmwareTables function. /// /// /// /// A pointer to a buffer that receives the requested firmware table. If this parameter is NULL, the return value is the /// required buffer size. /// /// For more information on the contents of this buffer, see the Remarks section. /// /// The size of the pFirmwareTableBuffer buffer, in bytes. /// /// /// If the function succeeds, the return value is the number of bytes written to the buffer. This value will always be less than or /// equal to BufferSize. /// /// /// If the function fails because the buffer is not large enough, the return value is the required buffer size, in bytes. This value /// is always greater than BufferSize. /// /// If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError. /// // UINT WINAPI GetSystemFirmwareTable( _In_ DWORD FirmwareTableProviderSignature, _In_ DWORD FirmwareTableID, _Out_ PVOID // pFirmwareTableBuffer, _In_ DWORD BufferSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724379(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724379")] public static extern uint GetSystemFirmwareTable(FirmwareTableProviderId FirmwareTableProviderSignature, uint FirmwareTableID, IntPtr pFirmwareTableBuffer, uint BufferSize); /// /// Retrieves information about the current system. /// To retrieve accurate information for an application running on WOW64, call the GetNativeSystemInfo function. /// /// A pointer to a SYSTEM_INFO structure that receives the information. /// This function does not return a value. // void WINAPI GetSystemInfo( _Out_ LPSYSTEM_INFO lpSystemInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724381(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724381")] public static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo); /// Retrieves the current size of the registry and the maximum size that the registry is allowed to attain on the system. /// /// A pointer to a variable that receives the maximum size that the registry is allowed to attain on this system, in bytes. /// /// A pointer to a variable that receives the current size of the registry, in bytes. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI GetSystemRegistryQuota( _Out_opt_ PDWORD pdwQuotaAllowed, _Out_opt_ PDWORD pdwQuotaUsed); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724387(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724387")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetSystemRegistryQuota(out uint pdwQuotaAllowed, out uint pdwQuotaUsed); /// /// Retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC). /// To retrieve the current system date and time in local time, use the GetLocalTime function. /// /// /// A pointer to a SYSTEMTIME structure to receive the current system date and time. The lpSystemTime parameter must not be /// NULL. Using NULL will result in an access violation. /// /// This function does not return a value or provide extended error information. // void WINAPI GetSystemTime( _Out_ LPSYSTEMTIME lpSystemTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724390")] public static extern void GetSystemTime(out SYSTEMTIME lpSystemTime); /// /// Determines whether the system is applying periodic time adjustments to its time-of-day clock, and obtains the value and period of /// any such adjustments. /// /// /// A pointer to a variable that the function sets to the number of lpTimeIncrement100-nanosecond units added to the time-of-day /// clock for every period of time which actually passes as counted by the system. This value only has meaning if /// lpTimeAdjustmentDisabled is FALSE. /// /// /// A pointer to a variable that the function sets to the interval in 100-nanosecond units at which the system will add /// lpTimeAdjustment to the time-of-day clock. This value only has meaning if lpTimeAdjustmentDisabled is FALSE. /// /// /// A pointer to a variable that the function sets to indicate whether periodic time adjustment is in effect. /// /// A value of TRUE indicates that periodic time adjustment is disabled, and the system time-of-day clock advances at the /// normal rate. In this mode, the system may adjust the time of day using its own internal time synchronization mechanisms. These /// internal time synchronization mechanisms may cause the time-of-day clock to change during the normal course of the system /// operation, which can include noticeable jumps in time as deemed necessary by the system. /// /// /// A value of FALSE indicates that periodic time adjustment is being used to adjust the time-of-day clock. For each /// lpTimeIncrement period of time that actually passes, lpTimeAdjustment will be added to the time of day. If the lpTimeAdjustment /// value is smaller than lpTimeIncrement, the system time-of-day clock will advance at a rate slower than normal. If the /// lpTimeAdjustment value is larger than lpTimeIncrement, the time-of-day clock will advance at a rate faster than normal. If /// lpTimeAdjustment equals lpTimeIncrement, the time-of-day clock will advance at its normal speed. The lpTimeAdjustment value can /// be set by calling SetSystemTimeAdjustment. The lpTimeIncrement value is fixed by the system upon start, and does not /// change during system operation. In this mode, the system will not interfere with the time adjustment scheme, and will not attempt /// to synchronize time of day on its own via other techniques. /// /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI GetSystemTimeAdjustment( _Out_ PDWORD lpTimeAdjustment, _Out_ PDWORD lpTimeIncrement, _Out_ PBOOL // lpTimeAdjustmentDisabled); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724394(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724394")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetSystemTimeAdjustment(out uint lpTimeAdjustment, out uint lpTimeIncrement, [MarshalAs(UnmanagedType.Bool)] out bool lpTimeAdjustmentDisabled); /// /// /// Determines whether the system is applying periodic, programmed time adjustments to its time-of-day clock, and obtains the value /// and period of any such adjustments. /// /// /// /// Returns the adjusted clock update frequency. /// /// /// Returns the clock update frequency. /// /// /// Returns an indicator which specifies whether the time adjustment is enabled. /// /// A value of TRUE indicates that periodic adjustment is disabled. In this case, the system may attempt to keep the /// time-of-day clock in sync using its own internal mechanisms. This may cause time-of-day to periodically jump to the "correct time." /// /// /// A value of FALSE indicates that periodic, programmed time adjustment is being used to serialize time-of-day, and the /// system will not interfere or attempt to synchronize time-of-day on its own. /// /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// This function is used in algorithms that synchronize the time-of-day with another time source, using a programmed clock /// adjustment. To do this, the system computes the adjusted clock update frequency, and then this function allows the caller to /// obtain that value. /// /// /// Note For a complete code sample on how to enable system-time privileges, adjust the system clock, and display clock /// values, see SetSystemTimeAdjustmentPrecise. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getsystemtimeadjustmentprecise BOOL // GetSystemTimeAdjustmentPrecise( PDWORD64 lpTimeAdjustment, PDWORD64 lpTimeIncrement, PBOOL lpTimeAdjustmentDisabled ); [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)] [PInvokeData("sysinfoapi.h", MSDNShortId = "95EEE23D-01D8-49E1-BA64-49C07E8B1619")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetSystemTimeAdjustmentPrecise(out ulong lpTimeAdjustment, out ulong lpTimeIncrement, [MarshalAs(UnmanagedType.Bool)] out bool lpTimeAdjustmentDisabled); /// Retrieves the current system date and time. The information is in Coordinated Universal Time (UTC) format. /// /// A pointer to a FILETIME structure to receive the current system date and time in UTC format. /// /// This function does not return a value. // void WINAPI GetSystemTimeAsFileTime( _Out_ LPFILETIME lpSystemTimeAsFileTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724397(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724397")] public static extern void GetSystemTimeAsFileTime(out FILETIME lpSystemTimeAsFileTime); /// /// The GetSystemTimePreciseAsFileTime function retrieves the current system date and time with the highest possible level of /// precision (<1us). The retrieved information is in Coordinated Universal Time (UTC) format. /// /// /// Type: LPFILETIME /// A pointer to a FILETIME structure that contains the current system date and time in UTC format. /// /// This function doesn't return a value. // VOID WINAPI GetSystemTimePreciseAsFileTime( _Out_ LPFILETIME lpSystemTimeAsFileTime); https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "hh706895")] public static extern void GetSystemTimePreciseAsFileTime(out FILETIME lpSystemTimeAsFileTime); /// /// Retrieves the path of the shared Windows directory on a multi-user system. /// /// This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent /// data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath. /// /// /// /// A pointer to the buffer to receive the path. This path does not end with a backslash unless the Windows directory is the root /// directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this /// function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:\. /// /// The maximum size of the buffer specified by the lpBuffer parameter, in TCHARs. /// /// /// If the function succeeds, the return value is the length of the string copied to the buffer, in TCHARs, not including the /// terminating null character. /// /// /// If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // UINT WINAPI GetSystemWindowsDirectory( _Out_ LPTSTR lpBuffer, _In_ UINT uSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724403(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724403")] public static extern uint GetSystemWindowsDirectory(StringBuilder lpBuffer, uint uSize); /// /// Retrieves the path of the shared Windows directory on a multi-user system. /// /// This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent /// data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath. /// /// /// /// A pointer to the buffer to receive the path. This path does not end with a backslash unless the Windows directory is the root /// directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this /// function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:\. /// public static string GetSystemWindowsDirectory() => CallMethodWithStrBuf((sb, sz) => GetSystemWindowsDirectory(sb, sz), (uint)MAX_PATH, out var sysDir) != 0 ? sysDir : throw Win32Error.GetLastError().GetException(); /// Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days. /// The return value is the number of milliseconds that have elapsed since the system was started. // DWORD WINAPI GetTickCount(void); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724408%28v=vs.85%29.aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724408")] public static extern uint GetTickCount(); /// Retrieves the number of milliseconds that have elapsed since the system was started. /// The number of milliseconds. // ULONGLONG WINAPI GetTickCount64(void); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724411")] public static extern ulong GetTickCount64(); /// /// [ GetVersion may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper functions] /// /// With the release of Windows 8.1, the behavior of the GetVersion API has changed in the value it will return for the /// operating system version. The value returned by the GetVersion function now depends on how the application is manifested. /// /// /// Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application /// is manifested for a given operating system version, GetVersion will always return the version that the application is /// manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your /// application for Windows. /// /// /// /// /// If the function succeeds, the return value includes the major and minor version numbers of the operating system in the low-order /// word, and information about the operating system platform in the high-order word. /// /// /// For all platforms, the low-order word contains the version number of the operating system. The low-order byte of this word /// specifies the major version number, in hexadecimal notation. The high-order byte specifies the minor version (revision) number, /// in hexadecimal notation. The high-order bit is zero, the next 7 bits represent the build number, and the low-order byte is 5. /// /// // DWORD WINAPI GetVersion(void); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724439")] public static extern uint GetVersion(); /// /// [ GetVersionEx may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper functions] /// /// With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the /// operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested. /// /// /// Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application /// is manifested for a given operating system version, GetVersionEx will always return the version that the application is /// manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your /// application for Windows. /// /// /// /// An OSVERSIONINFO or OSVERSIONINFOEX structure that receives the operating system information. /// /// Before calling the GetVersionEx function, set the dwOSVersionInfoSize member of the structure as appropriate to /// indicate which data structure is being passed to this function. /// /// /// /// If the function succeeds, the return value is a nonzero value. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. The function fails /// if you specify an invalid value for the dwOSVersionInfoSize member of the OSVERSIONINFO or OSVERSIONINFOEX structure. /// /// // BOOL WINAPI GetVersionEx( _Inout_ LPOSVERSIONINFO lpVersionInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724451")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetVersionEx(ref OSVERSIONINFOEX lpVersionInfo); /// /// Retrieves the path of the Windows directory. /// /// This function is provided primarily for compatibility with legacy applications. New applications should store code in the Program /// Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath. /// /// /// /// A pointer to a buffer that receives the path. This path does not end with a backslash unless the Windows directory is the root /// directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this /// function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:\. /// /// /// The maximum size of the buffer specified by the lpBuffer parameter, in TCHARs. This value should be set to MAX_PATH. /// /// /// /// If the function succeeds, the return value is the length of the string copied to the buffer, in TCHARs, not including the /// terminating null character. /// /// /// If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // UINT WINAPI GetWindowsDirectory( _Out_ LPTSTR lpBuffer, _In_ UINT uSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724454(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724454")] public static extern uint GetWindowsDirectory(StringBuilder lpBuffer, uint uSize); /// /// Retrieves the path of the Windows directory. /// /// This function is provided primarily for compatibility with legacy applications. New applications should store code in the Program /// Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath. /// /// /// /// Receives the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if /// the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this function is C:\Windows. If /// the system was installed in the root directory of drive C, the path retrieved is C:\. /// public static string GetWindowsDirectory() => CallMethodWithStrBuf((sb, sz) => GetWindowsDirectory(sb, sz), (uint)MAX_PATH, out var sysDir) != 0 ? sysDir : throw Win32Error.GetLastError().GetException(); /// /// [ GlobalMemoryStatus can return incorrect information. Use the GlobalMemoryStatusEx function instead.] /// Retrieves information about the system's current usage of both physical and virtual memory. /// /// /// A pointer to a MEMORYSTATUS structure. The GlobalMemoryStatus function stores information about current memory /// availability into this structure. /// /// This function does not return a value. // void WINAPI GlobalMemoryStatus( _Out_ LPMEMORYSTATUS lpBuffer); https://msdn.microsoft.com/en-us/library/windows/desktop/aa366586(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "aa366586")] public static extern void GlobalMemoryStatus(ref MEMORYSTATUS lpBuffer); /// Retrieves information about the system's current usage of both physical and virtual memory. /// A pointer to a MEMORYSTATUSEX structure that receives information about current memory availability. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI GlobalMemoryStatusEx( _Inout_ LPMEMORYSTATUSEX lpBuffer); https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "aa366589")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer); /// /// Installs the certificate information specified in the resource file, which is linked into the ELAM driver at build time. This API /// is used by anti-malware vendors to launch the anti-malware software's user-mode service as protected. For more information, see /// Protecting Anti-Malware Services. /// /// /// A handle to an ELAM driver file which contains the resource file with the certificate information. The handle to the ELAM driver /// file must be opened for read access only and must not be shared for write access. /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. To get extended error information, call GetLastError. /// // BOOL WINAPI InstallELAMCertificateInfo( _In_ HANDLE ELAMFile); https://msdn.microsoft.com/en-us/library/windows/desktop/dn369255(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Windows.h", MSDNShortId = "dn369255")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InstallELAMCertificateInfo(HFILE ELAMFile); /// /// /// Sets a new NetBIOS name for the local computer. The name is stored in the registry and the name change takes effect the next time /// the user restarts the computer. /// /// /// If the local computer is a node in a cluster, SetComputerName sets NetBIOS name of the local computer, not that of the /// cluster virtual server. /// /// To set the DNS host name or the DNS domain name, call the SetComputerNameEx function. /// /// /// /// The computer name that will take effect the next time the computer is started. The name must not be longer than /// MAX_COMPUTERNAME_LENGTH characters. /// /// /// The standard character set includes letters, numbers, and the following symbols: ! @ # $ % ^ & ' ) ( . - _ { } ~ . If this /// parameter contains one or more characters that are outside the standard character set, SetComputerName returns ERROR_INVALID_PARAMETER. /// /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI SetComputerName( _In_ LPCTSTR lpComputerName); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724930(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724930")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetComputerName(string lpComputerName); /// /// Sets a new NetBIOS or DNS name for the local computer. Name changes made by SetComputerNameEx do not take effect until the /// user restarts the computer. /// /// /// /// The type of name to be set. This parameter can be one of the following values from the COMPUTER_NAME_FORMAT enumeration type. /// /// /// /// /// Value /// Meaning /// /// /// ComputerNamePhysicalDnsDomain /// Sets the primary DNS suffix of the computer. /// /// /// ComputerNamePhysicalDnsHostname /// /// Sets the NetBIOS and the Computer Name (the first label of the full DNS name) to the name specified in lpBuffer. If the name /// exceeds MAX_COMPUTERNAME_LENGTH characters, the NetBIOS name is truncated to MAX_COMPUTERNAME_LENGTH characters, not including /// the terminating null character. /// /// /// /// ComputerNamePhysicalNetBIOS /// /// Sets the NetBIOS name to the name specified in lpBuffer. The name cannot exceed MAX_COMPUTERNAME_LENGTH characters, not including /// the terminating null character. Warning: Using this option to set the NetBIOS name breaks the convention of interdependent /// NetBIOS and DNS names. Applications that use the DnsHostnameToComputerName function to derive the NetBIOS name from the first /// label of the DNS name will fail if this convention is broken. /// /// /// /// /// /// /// The new name. The name cannot include control characters, leading or trailing spaces, or any of the following characters: " / \ [ /// ] : | < > + = ; , ? /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI SetComputerNameEx( _In_ COMPUTER_NAME_FORMAT NameType, _In_ LPCTSTR lpBuffer); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724931(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724931")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType, string lpBuffer); /// /// Sets a new NetBIOS or DNS name for the local computer. Name changes made by SetComputerNameEx do not take effect until the /// user restarts the computer. /// /// /// /// The type of name to be set. This parameter can be one of the following values from the COMPUTER_NAME_FORMAT enumeration type. /// /// /// /// /// Value /// Meaning /// /// /// ComputerNamePhysicalDnsDomain /// Sets the primary DNS suffix of the computer. /// /// /// ComputerNamePhysicalDnsHostname /// /// Sets the NetBIOS and the Computer Name (the first label of the full DNS name) to the name specified in lpBuffer. If the name /// exceeds MAX_COMPUTERNAME_LENGTH characters, the NetBIOS name is truncated to MAX_COMPUTERNAME_LENGTH characters, not including /// the terminating null character. /// /// /// /// ComputerNamePhysicalNetBIOS /// /// Sets the NetBIOS name to the name specified in lpBuffer. The name cannot exceed MAX_COMPUTERNAME_LENGTH characters, not including /// the terminating null character. Warning: Using this option to set the NetBIOS name breaks the convention of interdependent /// NetBIOS and DNS names. Applications that use the DnsHostnameToComputerName function to derive the NetBIOS name from the first /// label of the DNS name will fail if this convention is broken. /// /// /// /// /// /// The flags. /// /// The new name. The name cannot include control characters, leading or trailing spaces, or any of the following characters: " / \ [ /// ] : | < > + = ; , ? /// /// /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// [DllImport(Lib.Kernel32, SetLastError = true, EntryPoint = "SetComputerNameEx2W", CharSet = CharSet.Unicode)] [PInvokeData("Winbase.h")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetComputerNameEx2(COMPUTER_NAME_FORMAT NameType, SCEX2 Flags, string lpBuffer); /// Sets the value of the specified firmware environment variable. /// The name of the firmware environment variable. The pointer must not be NULL. /// /// The GUID that represents the namespace of the firmware environment variable. The GUID must be a string in the format /// "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}". If the system does not support GUID-based namespaces, this parameter is ignored. /// /// A pointer to the new value for the firmware environment variable. /// /// The size of the pBuffer buffer, in bytes. If this parameter is zero, the firmware environment variable is deleted. /// /// /// If the function succeeds, the return value is a nonzero value. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible error /// codes include ERROR_INVALID_FUNCTION. /// /// // BOOL WINAPI SetFirmwareEnvironmentVariable( _In_ LPCTSTR lpName, _In_ LPCTSTR lpGuid, _In_ PVOID pBuffer, _In_ DWORD nSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724934(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms724934")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetFirmwareEnvironmentVariable(string lpName, string lpGuid, [In] IntPtr pBuffer, uint nSize); /// Sets the current local time and date. /// /// A pointer to a SYSTEMTIME structure that contains the new local date and time. /// The wDayOfWeek member of the SYSTEMTIME structure is ignored. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI SetLocalTime( _In_ const SYSTEMTIME *lpSystemTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724936(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724936")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetLocalTime(in SYSTEMTIME lpSystemTime); /// Sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC). /// /// A pointer to a SYSTEMTIME structure that contains the new system date and time. /// The wDayOfWeek member of the SYSTEMTIME structure is ignored. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI SetSystemTime( _In_ const SYSTEMTIME *lpSystemTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724942(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724942")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetSystemTime(in SYSTEMTIME lpSystemTime); /// /// Enables or disables periodic time adjustments to the system's time-of-day clock. When enabled, such time adjustments can be used /// to synchronize the time of day with some other source of time information. /// /// /// This value represents the number of 100-nanosecond units added to the system time-of-day for each lpTimeIncrement period of time /// that actually passes. Call GetSystemTimeAdjustment to obtain the lpTimeIncrement value. See remarks. /// /// /// The time adjustment mode that the system is to use. Periodic system time adjustments can be disabled or enabled. /// /// A value of TRUE specifies that periodic time adjustment is to be disabled. When disabled, the value of dwTimeAdjustment is /// ignored, and the system may adjust the time of day using its own internal time synchronization mechanisms. These internal time /// synchronization mechanisms may cause the time-of-day clock to change during the normal course of the system operation, which can /// include noticeable jumps in time as deemed necessary by the system. /// /// /// A value of FALSE specifies that periodic time adjustment is to be enabled, and will be used to adjust the time-of-day /// clock. The system will not interfere with the time adjustment scheme, and will not attempt to synchronize time of day on its own. /// /// /// /// If the function succeeds, the return value is non-zero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. One way the /// function can fail is if the caller does not possess the SE_SYSTEMTIME_NAME privilege. /// /// // BOOL WINAPI SetSystemTimeAdjustment( _In_ DWORD dwTimeAdjustment, _In_ BOOL bTimeAdjustmentDisabled); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724943(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724943")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetSystemTimeAdjustment(uint dwTimeAdjustment, [MarshalAs(UnmanagedType.Bool)] bool bTimeAdjustmentDisabled); /// /// Enables or disables periodic time adjustments to the system's time-of-day clock. When enabled, such time adjustments can be used /// to synchronize the time of day with some other source of time information. /// /// Supplies the adjusted clock update frequency. /// /// Supplies a flag which specifies the time adjustment mode that the system is to use. /// /// A value of TRUE indicates that the system should synchronize time-of-day using its own internal mechanisms. In this case, /// the value of dwTimeAdjustment is ignored. /// /// /// A value of FALSE indicates that the application is in control, and that the specified value of dwTimeAdjustment is to be /// added to the time-of-day clock at each clock update interrupt. /// /// /// /// If the function succeeds, the return value is non-zero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. One way the function can /// fail is if the caller does not possess the SE_SYSTEMTIME_NAME privilege. /// /// /// /// /// To use this function, the caller must have system-time privilege (SE_SYSTEMTIME_NAME). This privilege is disabled by default. Use /// the AdjustTokenPrivileges function to enable the privilege before calling this function, then disable the privilege after the /// function call. For more information, see the code example below. /// /// Examples /// /// This sample demonstrates how to enable system-time privileges, adjust the system clock using GetSystemTimeAdjustmentPrecise and /// SetSystemTimeAdjustmentPrecise, and how to neatly print the current system-time adjustments. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-setsystemtimeadjustmentprecise BOOL // SetSystemTimeAdjustmentPrecise( DWORD64 dwTimeAdjustment, BOOL bTimeAdjustmentDisabled ); [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)] [PInvokeData("sysinfoapi.h", MSDNShortId = "8B429BFC-9781-4434-9A2F-9E50E2BF299A")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetSystemTimeAdjustmentPrecise(ulong dwTimeAdjustment, [MarshalAs(UnmanagedType.Bool)] bool bTimeAdjustmentDisabled); /// /// Compares a set of operating system version requirements to the corresponding values for the currently running version of the /// system. This function is subject to manifest-based behavior. For more information, see the Remarks section. /// /// /// /// A pointer to an OSVERSIONINFOEX structure containing the operating system version requirements to compare. The dwTypeMask /// parameter indicates the members of this structure that contain information to compare. /// /// /// You must set the dwOSVersionInfoSize member of this structure to . You must also specify valid data for the members /// indicated by dwTypeMask. The function ignores structure members for which the corresponding dwTypeMask bit is not set. /// /// /// /// /// A mask that indicates the members of the OSVERSIONINFOEX structure to be tested. This parameter can be one or more of the /// following values. /// /// /// /// /// Value /// Meaning /// /// /// VER_BUILDNUMBER0x0000004 /// dwBuildNumber /// /// /// VER_MAJORVERSION0x0000002 /// /// dwMajorVersionIf you are testing the major version, you must also test the minor version and the service pack major and minor versions. /// /// /// /// VER_MINORVERSION0x0000001 /// dwMinorVersion /// /// /// VER_PLATFORMID0x0000008 /// dwPlatformId /// /// /// VER_SERVICEPACKMAJOR0x0000020 /// wServicePackMajor /// /// /// VER_SERVICEPACKMINOR0x0000010 /// wServicePackMinor /// /// /// VER_SUITENAME0x0000040 /// wSuiteMask /// /// /// VER_PRODUCT_TYPE0x0000080 /// wProductType /// /// /// /// /// /// The type of comparison to be used for each lpVersionInfo member being compared. To build this value, call the /// VerSetConditionMask function or the VER_SET_CONDITION macro once for each OSVERSIONINFOEX member being compared. /// /// /// If the currently running operating system satisfies the specified requirements, the return value is a nonzero value. /// If the current system does not satisfy the requirements, the return value is zero and GetLastError returns ERROR_OLD_WIN_VERSION. /// If the function fails, the return value is zero and GetLastError returns an error code other than ERROR_OLD_WIN_VERSION. /// // BOOL WINAPI VerifyVersionInfo( _In_ LPOSVERSIONINFOEX lpVersionInfo, _In_ DWORD dwTypeMask, _In_ DWORDLONG dwlConditionMask); https://msdn.microsoft.com/en-us/library/windows/desktop/ms725492(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winbase.h", MSDNShortId = "ms725492")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool VerifyVersionInfo(ref OSVERSIONINFOEX lpVersionInfo, VERSION_MASK dwTypeMask, ulong dwlConditionMask); /// /// Sets the bits of a 64-bit value to indicate the comparison operator to use for a specified operating system version attribute. /// This function is used to build the dwlConditionMask parameter of the VerifyVersionInfo function. /// /// /// /// A value to be passed as the dwlConditionMask parameter of the VerifyVersionInfo function. The function stores the /// comparison information in the bits of this variable. /// /// /// Before the first call to VerSetCondition, initialize this variable to zero. For subsequent calls, pass in the variable /// used in the previous call. /// /// /// /// /// A mask that indicates the member of the OSVERSIONINFOEX structure whose comparison operator is being set. This value /// corresponds to one of the bits specified in the dwTypeMask parameter for the VerifyVersionInfo function. This parameter /// can be one of the following values. /// /// /// /// /// Value /// Meaning /// /// /// VER_BUILDNUMBER0x0000004 /// dwBuildNumber /// /// /// VER_MAJORVERSION0x0000002 /// dwMajorVersion /// /// /// VER_MINORVERSION0x0000001 /// dwMinorVersion /// /// /// VER_PLATFORMID0x0000008 /// dwPlatformId /// /// /// VER_PRODUCT_TYPE0x0000080 /// wProductType /// /// /// VER_SERVICEPACKMAJOR0x0000020 /// wServicePackMajor /// /// /// VER_SERVICEPACKMINOR0x0000010 /// wServicePackMinor /// /// /// VER_SUITENAME0x0000040 /// wSuiteMask /// /// /// /// /// /// /// The operator to be used for the comparison. The VerifyVersionInfo function uses this operator to compare a specified /// attribute value to the corresponding value for the currently running system. /// /// For all values of dwTypeBitMask other than VER_SUITENAME, this parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// VER_EQUAL1 /// The current value must be equal to the specified value. /// /// /// VER_GREATER2 /// The current value must be greater than the specified value. /// /// /// VER_GREATER_EQUAL3 /// The current value must be greater than or equal to the specified value. /// /// /// VER_LESS4 /// The current value must be less than the specified value. /// /// /// VER_LESS_EQUAL5 /// The current value must be less than or equal to the specified value. /// /// /// /// If dwTypeBitMask is VER_SUITENAME, this parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// VER_AND6 /// All product suites specified in the wSuiteMask member must be present in the current system. /// /// /// VER_OR7 /// At least one of the specified product suites must be present in the current system. /// /// /// /// /// The function returns the condition mask value. // ULONGLONG WINAPI VerSetConditionMask( _In_ ULONGLONG dwlConditionMask, _In_ DWORD dwTypeBitMask, _In_ BYTE dwConditionMask); https://msdn.microsoft.com/en-us/library/windows/desktop/ms725493(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winnt.h", MSDNShortId = "ms725493")] public static extern ulong VerSetConditionMask(ulong dwlConditionMask, VERSION_MASK dwTypeBitMask, VERSION_CONDITION dwConditionMask); /// Describes the cache attributes. // typedef struct _CACHE_DESCRIPTOR { BYTE Level; BYTE Associativity; WORD LineSize; DWORD Size; PROCESSOR_CACHE_TYPE Type;} CACHE_DESCRIPTOR, // *PCACHE_DESCRIPTOR; https://msdn.microsoft.com/en-us/library/windows/desktop/ms681979(v=vs.85).aspx [PInvokeData("WinNT.h", MSDNShortId = "ms681979")] [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct CACHE_DESCRIPTOR { /// /// The cache level. This member can currently be one of the following values; other values may be supported in the future. /// /// /// /// Value /// Meaning /// /// /// 1 /// L1 /// /// /// 2 /// L2 /// /// /// 3 /// L3 /// /// /// /// public byte Level; /// The cache associativity. If this member is CACHE_FULLY_ASSOCIATIVE (0xFF), the cache is fully associative. public byte Associativity; /// The cache line size, in bytes. public ushort LineSize; /// The cache size, in bytes. public uint Size; /// The cache type. This member is a PROCESSOR_CACHE_TYPE value. public PROCESSOR_CACHE_TYPE Type; } /// /// Describes cache attributes. This structure is used with the GetLogicalProcessorInformationEx function. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_cache_relationship typedef struct _CACHE_RELATIONSHIP { BYTE // Level; BYTE Associativity; WORD LineSize; DWORD CacheSize; PROCESSOR_CACHE_TYPE Type; BYTE Reserved[20]; GROUP_AFFINITY GroupMask; // } CACHE_RELATIONSHIP, *PCACHE_RELATIONSHIP; [PInvokeData("winnt.h", MSDNShortId = "f8fe521b-02d6-4c58-8ef8-653280add111")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct CACHE_RELATIONSHIP { /// /// The cache level. This member can be one of the following values. /// /// /// Value /// Meaning /// /// /// 1 /// L1 /// /// /// 2 /// L2 /// /// /// 3 /// L3 /// /// /// public byte Level; /// /// The cache associativity. If this member is CACHE_FULLY_ASSOCIATIVE (0xFF), the cache is fully associative. /// public byte Associativity; /// /// The cache line size, in bytes. /// public ushort LineSize; /// /// The cache size, in bytes. /// public uint CacheSize; /// /// The cache type. This member is a PROCESSOR_CACHE_TYPE value. /// public PROCESSOR_CACHE_TYPE Type; /// /// This member is reserved. /// private readonly uint Reserved1; private readonly uint Reserved2; private readonly uint Reserved3; private readonly uint Reserved4; private readonly uint Reserved5; /// /// A GROUP_AFFINITY structure that specifies a group number and processor affinity within the group. /// public GROUP_AFFINITY GroupMask; } /// /// Represents information about processor groups. This structure is used with the GetLogicalProcessorInformationEx function. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_group_relationship typedef struct _GROUP_RELATIONSHIP { WORD // MaximumGroupCount; WORD ActiveGroupCount; BYTE Reserved[20]; PROCESSOR_GROUP_INFO GroupInfo[ANYSIZE_ARRAY]; } GROUP_RELATIONSHIP, *PGROUP_RELATIONSHIP; [PInvokeData("winnt.h", MSDNShortId = "3529ddef-04c5-4573-877d-c225da684e38")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct GROUP_RELATIONSHIP { /// /// The maximum number of processor groups on the system. /// public ushort MaximumGroupCount; /// /// /// The number of active groups on the system. This member indicates the number of PROCESSOR_GROUP_INFO structures in the /// GroupInfo array. /// /// public ushort ActiveGroupCount; /// /// This member is reserved. /// private readonly uint Reserved1; private readonly uint Reserved2; private readonly uint Reserved3; private readonly uint Reserved4; private readonly uint Reserved5; private PROCESSOR_GROUP_INFO _GroupInfo; /// /// /// An array of PROCESSOR_GROUP_INFO structures. Each structure represents the number and affinity of processors in an active /// group on the system. /// /// public PROCESSOR_GROUP_INFO[] GroupInfo { get { unsafe { fixed (void* p = &_GroupInfo) { return ((IntPtr)p).ToArray(ActiveGroupCount); } } } } } /// /// Contains information about the current state of both physical and virtual memory. The GlobalMemoryStatus function stores /// information in a MEMORYSTATUS structure. /// // typedef struct _MEMORYSTATUS { DWORD dwLength; DWORD dwMemoryLoad; SIZE_T dwTotalPhys; SIZE_T dwAvailPhys; SIZE_T dwTotalPageFile; // SIZE_T dwAvailPageFile; SIZE_T dwTotalVirtual; SIZE_T dwAvailVirtual;} MEMORYSTATUS, *LPMEMORYSTATUS; https://msdn.microsoft.com/en-us/library/windows/desktop/aa366772(v=vs.85).aspx [PInvokeData("WinBase.h", MSDNShortId = "aa366772")] [StructLayout(LayoutKind.Sequential)] public struct MEMORYSTATUS { /// /// The size of the MEMORYSTATUS data structure, in bytes. You do not need to set this member before calling the /// GlobalMemoryStatus function; the function sets it. /// public uint dwLength; /// /// A number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory /// use and 100 indicates full memory use). /// public uint dwMemoryLoad; /// The amount of actual physical memory, in bytes. public SizeT dwTotalPhys; /// /// The amount of physical memory currently available, in bytes. This is the amount of physical memory that can be immediately /// reused without having to write its contents to disk first. It is the sum of the size of the standby, free, and zero lists. /// public SizeT dwAvailPhys; /// /// The current size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a /// small overhead. /// public SizeT dwTotalPageFile; /// /// The maximum amount of memory the current process can commit, in bytes. This value should be smaller than the system-wide /// available commit. To calculate this value, call GetPerformanceInfo and subtract the value of CommitTotal from CommitLimit. /// public SizeT dwAvailPageFile; /// /// The size of the user-mode portion of the virtual address space of the calling process, in bytes. This value depends on the /// type of process, the type of processor, and the configuration of the operating system. For example, this value is /// approximately 2 GB for most 32-bit processes on an x86 processor and approximately 3 GB for 32-bit processes that are large /// address aware running on a system with 4 GT RAM Tuning enabled. /// public SizeT dwTotalVirtual; /// /// The amount of unreserved and uncommitted memory currently in the user-mode portion of the virtual address space of the /// calling process, in bytes. /// public SizeT dwAvailVirtual; /// Gets a default instance with the size pre-set. public static readonly MEMORYSTATUS Default = new MEMORYSTATUS { dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUS)) }; } /// /// Contains information about the current state of both physical and virtual memory, including extended memory. The /// GlobalMemoryStatusEx function stores information in this structure. /// // typedef struct _MEMORYSTATUSEX { DWORD dwLength; DWORD dwMemoryLoad; DWORDLONG ullTotalPhys; DWORDLONG ullAvailPhys; DWORDLONG // ullTotalPageFile; DWORDLONG ullAvailPageFile; DWORDLONG ullTotalVirtual; DWORDLONG ullAvailVirtual; DWORDLONG // ullAvailExtendedVirtual;} MEMORYSTATUSEX, // *LPMEMORYSTATUSEX; https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx [PInvokeData("WinBase.h", MSDNShortId = "aa366770")] [StructLayout(LayoutKind.Sequential)] public struct MEMORYSTATUSEX { /// The size of the structure, in bytes. You must set this member before calling GlobalMemoryStatusEx. public uint dwLength; /// /// A number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory /// use and 100 indicates full memory use). /// public uint dwMemoryLoad; /// The amount of actual physical memory, in bytes. public ulong ullTotalPhys; /// /// The amount of physical memory currently available, in bytes. This is the amount of physical memory that can be immediately /// reused without having to write its contents to disk first. It is the sum of the size of the standby, free, and zero lists. /// public ulong ullAvailPhys; /// /// The current committed memory limit for the system or the current process, whichever is smaller, in bytes. To get the /// system-wide committed memory limit, call GetPerformanceInfo. /// public ulong ullTotalPageFile; /// /// The maximum amount of memory the current process can commit, in bytes. This value is equal to or smaller than the system-wide /// available commit value. To calculate the system-wide available commit value, call GetPerformanceInfo and subtract the /// value of CommitTotal from the value of CommitLimit. /// public ulong ullAvailPageFile; /// /// The size of the user-mode portion of the virtual address space of the calling process, in bytes. This value depends on the /// type of process, the type of processor, and the configuration of the operating system. For example, this value is /// approximately 2 GB for most 32-bit processes on an x86 processor and approximately 3 GB for 32-bit processes that are large /// address aware running on a system with 4-gigabyte tuning enabled. /// public ulong ullTotalVirtual; /// /// The amount of unreserved and uncommitted memory currently in the user-mode portion of the virtual address space of the /// calling process, in bytes. /// public ulong ullAvailVirtual; /// Reserved. This value is always 0. public ulong ullAvailExtendedVirtual; /// Gets a default instance with the size pre-set. public static readonly MEMORYSTATUSEX Default = new MEMORYSTATUSEX { dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX)) }; } /// /// /// Represents information about a NUMA node in a processor group. This structure is used with the GetLogicalProcessorInformationEx function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_numa_node_relationship typedef struct _NUMA_NODE_RELATIONSHIP // { DWORD NodeNumber; BYTE Reserved[20]; GROUP_AFFINITY GroupMask; } NUMA_NODE_RELATIONSHIP, *PNUMA_NODE_RELATIONSHIP; [PInvokeData("winnt.h", MSDNShortId = "a4e4c994-c4af-4b4f-8684-6037bcba35a9")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct NUMA_NODE_RELATIONSHIP { /// /// The number of the NUMA node. /// public uint NodeNumber; /// /// This member is reserved. /// private readonly uint Reserved1; private readonly uint Reserved2; private readonly uint Reserved3; private readonly uint Reserved4; private readonly uint Reserved5; /// /// A GROUP_AFFINITY structure that specifies a group number and processor affinity within the group. /// public GROUP_AFFINITY GroupMask; } /// /// Contains operating system version information. The information includes major and minor version numbers, a build number, a /// platform identifier, and information about product suites and the latest Service Pack installed on the system. This structure is /// used with the GetVersionEx and VerifyVersionInfo functions. /// // typedef struct _OSVERSIONINFOEX { DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; DWORD dwBuildNumber; // DWORD dwPlatformId; TCHAR szCSDVersion[128]; WORD wServicePackMajor; WORD wServicePackMinor; WORD wSuiteMask; BYTE wProductType; // BYTE wReserved;} OSVERSIONINFOEX, // *POSVERSIONINFOEX, *LPOSVERSIONINFOEX; https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx [PInvokeData("Winnt.h", MSDNShortId = "ms724833")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] public struct OSVERSIONINFOEX { /// The size of this data structure, in bytes. Set this member to . public uint dwOSVersionInfoSize; /// The major version number of the operating system. For more information, see Remarks. public uint dwMajorVersion; /// The minor version number of the operating system. For more information, see Remarks. public uint dwMinorVersion; /// The build number of the operating system. public uint dwBuildNumber; /// The operating system platform. This member can be VER_PLATFORM_WIN32_NT (2). public PlatformID dwPlatformId; /// /// A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no /// Service Pack has been installed, the string is empty. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string szCSDVersion; /// /// The major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the major /// version number is 3. If no Service Pack has been installed, the value is zero. /// public ushort wServicePackMajor; /// /// The minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the minor /// version number is 0. /// public ushort wServicePackMinor; /// /// /// A bit mask that identifies the product suites available on the system. This member can be a combination of the following values. /// /// /// /// /// Value /// Meaning /// /// /// VER_SUITE_BACKOFFICE0x00000004 /// Microsoft BackOffice components are installed. /// /// /// VER_SUITE_BLADE0x00000400 /// Windows Server 2003, Web Edition is installed. /// /// /// VER_SUITE_COMPUTE_SERVER0x00004000 /// Windows Server 2003, Compute Cluster Edition is installed. /// /// /// VER_SUITE_DATACENTER0x00000080 /// Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed. /// /// /// VER_SUITE_ENTERPRISE0x00000002 /// /// Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer /// to the Remarks section for more information about this bit flag. /// /// /// /// VER_SUITE_EMBEDDEDNT0x00000040 /// Windows XP Embedded is installed. /// /// /// VER_SUITE_PERSONAL0x00000200 /// Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed. /// /// /// VER_SUITE_SINGLEUSERTS0x00000100 /// /// Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in /// application server mode. /// /// /// /// VER_SUITE_SMALLBUSINESS0x00000001 /// /// Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. /// Refer to the Remarks section for more information about this bit flag. /// /// /// /// VER_SUITE_SMALLBUSINESS_RESTRICTED0x00000020 /// /// Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for /// more information about this bit flag. /// /// /// /// VER_SUITE_STORAGE_SERVER0x00002000 /// Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed. /// /// /// VER_SUITE_TERMINAL0x00000010 /// /// Terminal Services is installed. This value is always set.If VER_SUITE_TERMINAL is set but VER_SUITE_SINGLEUSERTS is not set, /// the system is running in application server mode. /// /// /// /// VER_SUITE_WH_SERVER0x00008000 /// Windows Home Server is installed. /// /// /// VER_SUITE_MULTIUSERTS0x00020000 /// AppServer mode is enabled. /// /// /// /// public SuiteMask wSuiteMask; /// /// Any additional information about the system. This member can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// VER_NT_DOMAIN_CONTROLLER0x0000002 /// /// The system is a domain controller and the operating system is Windows Server 2012 , Windows Server 2008 R2, Windows Server /// 2008, Windows Server 2003, or Windows 2000 Server. /// /// /// /// VER_NT_SERVER0x0000003 /// /// The operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows /// 2000 Server.Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER. /// /// /// /// VER_NT_WORKSTATION0x0000001 /// /// The operating system is Windows 8, Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows /// 2000 Professional. /// /// /// /// /// public ProductType wProductType; /// Reserved for future use. public byte wReserved; /// Gets a default instance with the size pre-set. public static readonly OSVERSIONINFOEX Default = new OSVERSIONINFOEX { dwOSVersionInfoSize = (uint)Marshal.SizeOf(typeof(OSVERSIONINFOEX)) }; } /// /// Represents the number and affinity of processors in a processor group. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_processor_group_info typedef struct _PROCESSOR_GROUP_INFO { // BYTE MaximumProcessorCount; BYTE ActiveProcessorCount; BYTE Reserved[38]; KAFFINITY ActiveProcessorMask; } PROCESSOR_GROUP_INFO, *PPROCESSOR_GROUP_INFO; [PInvokeData("winnt.h", MSDNShortId = "6ff9cc3c-34e7-4dc4-94cd-6ed278dfaa03")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct PROCESSOR_GROUP_INFO { /// /// The maximum number of processors in the group. /// public byte MaximumProcessorCount; /// /// The number of active processors in the group. /// public byte ActiveProcessorCount; /// /// This member is reserved. /// private readonly ushort Reserved1; private readonly uint Reserved2; private readonly uint Reserved3; private readonly uint Reserved4; private readonly uint Reserved5; private readonly uint Reserved6; private readonly uint Reserved7; private readonly uint Reserved8; private readonly uint Reserved9; private readonly uint Reserved10; /// /// A bitmap that specifies the affinity for zero or more active processors within the group. /// public UIntPtr ActiveProcessorMask; } /// /// /// Represents information about affinity within a processor group. This structure is used with the GetLogicalProcessorInformationEx function. /// /// /// /// /// The PROCESSOR_RELATIONSHIP structure describes the logical processors associated with either a processor core or a /// processor package. /// /// If the PROCESSOR_RELATIONSHIP structure represents a processor core, the GroupCount member is always 1. /// /// If the PROCESSOR_RELATIONSHIP structure represents a processor package, the GroupCount member is 1 only if all /// processors are in the same processor group. If the package contains more than one NUMA node, the system might assign different /// NUMA nodes to different processor groups. In this case, the GroupCount member is the number of groups to which NUMA nodes /// in the package are assigned. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_processor_relationship typedef struct _PROCESSOR_RELATIONSHIP // { BYTE Flags; BYTE EfficiencyClass; BYTE Reserved[20]; WORD GroupCount; GROUP_AFFINITY GroupMask[ANYSIZE_ARRAY]; } // PROCESSOR_RELATIONSHIP, *PPROCESSOR_RELATIONSHIP; [PInvokeData("winnt.h", MSDNShortId = "1efda80d-cf5b-4312-801a-ea3585b152ac")] [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct PROCESSOR_RELATIONSHIP { /// /// /// If the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is RelationProcessorCore, /// this member is LTP_PC_SMT if the core has more than one logical processor, or 0 if the core has one logical processor. /// /// /// If the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is /// RelationProcessorPackage, this member is always 0. /// /// public byte Flags; /// /// /// If the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is RelationProcessorCore, /// EfficiencyClass specifies the intrinsic tradeoff between performance and power for the applicable core. A core with a /// higher value for the efficiency class has intrinsically greater performance and less efficiency than a core with a lower /// value for the efficiency class. EfficiencyClass is only nonzero on systems with a heterogeneous set of cores. /// /// /// If the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is /// RelationProcessorPackage, EfficiencyClass is always 0. /// /// The minimum operating system version that supports this member is Windows 10. /// public byte EfficiencyClass; /// /// This member is reserved. /// private readonly ushort Reserved1; private readonly uint Reserved2; private readonly uint Reserved3; private readonly uint Reserved4; private readonly uint Reserved5; private readonly ushort Reserved6; /// /// This member specifies the number of entries in the GroupMask array. For more information, see Remarks. /// public ushort GroupCount; private GROUP_AFFINITY _GroupMask; /// /// An array of GROUP_AFFINITY structures. The GroupCount member specifies the number of structures in the array. Each /// structure in the array specifies a group number and processor affinity within the group. /// public GROUP_AFFINITY[] GroupMask { get { unsafe { fixed (void* p = &_GroupMask) { return ((IntPtr)p).ToArray(GroupCount); } } } } } /// /// Contains information about the current computer system. This includes the architecture and type of the processor, the number of /// processors in the system, the page size, and other such information. /// // typedef struct _SYSTEM_INFO { union { DWORD dwOemId; struct { WORD wProcessorArchitecture; WORD wReserved; }; }; DWORD dwPageSize; // LPVOID lpMinimumApplicationAddress; LPVOID lpMaximumApplicationAddress; DWORD_PTR dwActiveProcessorMask; DWORD // dwNumberOfProcessors; DWORD dwProcessorType; DWORD dwAllocationGranularity; WORD wProcessorLevel; WORD wProcessorRevision;} // SYSTEM_INFO; https://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx [PInvokeData("Winbase.h", MSDNShortId = "ms724958")] [StructLayout(LayoutKind.Sequential, Pack = 2)] public struct SYSTEM_INFO { /// /// The processor architecture of the installed operating system. This member can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// PROCESSOR_ARCHITECTURE_AMD649 /// x64 (AMD or Intel) /// /// /// PROCESSOR_ARCHITECTURE_ARM5 /// ARM /// /// /// PROCESSOR_ARCHITECTURE_ARM6412 /// ARM64 /// /// /// PROCESSOR_ARCHITECTURE_IA646 /// Intel Itanium-based /// /// /// PROCESSOR_ARCHITECTURE_INTEL0 /// x86 /// /// /// PROCESSOR_ARCHITECTURE_UNKNOWN0xffff /// Unknown architecture. /// /// /// /// public ProcessorArchitecture wProcessorArchitecture; /// This member is reserved for future use. public ushort wReserved; /// /// The page size and the granularity of page protection and commitment. This is the page size used by the VirtualAlloc function. /// public uint dwPageSize; /// A pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs). public IntPtr lpMinimumApplicationAddress; /// A pointer to the highest memory address accessible to applications and DLLs. public IntPtr lpMaximumApplicationAddress; /// /// A mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31. /// public UIntPtr dwActiveProcessorMask; /// /// The number of logical processors in the current group. To retrieve this value, use the GetLogicalProcessorInformation function. /// public uint dwNumberOfProcessors; /// /// An obsolete member that is retained for compatibility. Use the wProcessorArchitecture, wProcessorLevel, and /// wProcessorRevision members to determine the type of processor. /// public uint dwProcessorType; /// /// The granularity for the starting address at which virtual memory can be allocated. For more information, see VirtualAlloc. /// public uint dwAllocationGranularity; /// /// /// The architecture-dependent processor level. It should be used only for display purposes. To determine the feature set of a /// processor, use the IsProcessorFeaturePresent function. /// /// If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel is defined by the CPU vendor. /// If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1. /// public ushort wProcessorLevel; /// /// /// The architecture-dependent processor revision. The following table shows how the revision value is assembled for each type of /// processor architecture. /// /// /// /// /// Processor /// Value /// /// /// Intel Pentium, Cyrix, or NextGen 586 /// /// The high byte is the model and the low byte is the stepping. For example, if the value is xxyy, the model number and stepping /// can be displayed as /// follows: Model xx, Stepping yy /// /// /// /// Intel 80386 or 80486 /// /// A value of the form xxyz. If xx is equal to 0xFF, y - 0xA is the model number, and z is the stepping identifier.If xx is not /// equal to 0xFF, xx + 'A' is the stepping letter and yz is the minor stepping. /// /// /// /// ARM /// Reserved. /// /// /// /// public ushort wProcessorRevision; } /// /// Describes the relationship between the specified processor set. This structure is used with the /// GetLogicalProcessorInformation function. /// // typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION { ULONG_PTR ProcessorMask; LOGICAL_PROCESSOR_RELATIONSHIP Relationship; union // { struct { BYTE Flags; } ProcessorCore; struct { DWORD NodeNumber; } NumaNode; CACHE_DESCRIPTOR Cache; ULONGLONG Reserved[2]; };} // SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms686694(v=vs.85).aspx [PInvokeData("WinNT.h", MSDNShortId = "ms686694")] [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION { /// /// /// The processor mask identifying the processors described by this structure. A processor mask is a bit vector in which each set /// bit represents an active processor in the relationship. At least one bit will be set. /// /// On a system with more than 64 processors, the processor mask identifies processors in a single processor group. /// public UIntPtr ProcessorMask; /// /// /// The relationship between the processors identified by the value of the ProcessorMask member. This member can be one of /// the following LOGICAL_PROCESSOR_RELATIONSHIP values. /// /// /// /// /// Value /// Meaning /// /// /// RelationCache2 /// /// The specified logical processors share a cache. The Cache member contains additional information.Windows Server 2003: This /// value is not supported until Windows Server 2003 with SP1 and Windows XP Professional x64 Edition. /// /// /// /// RelationNumaNode1 /// The specified logical processors are part of the same NUMA node. The NumaNode member contains additional information. /// /// /// RelationProcessorCore0 /// The specified logical processors share a single processor core. The ProcessorCore member contains additional information. /// /// /// RelationProcessorPackage3 /// /// The specified logical processors share a physical package. There is no additional information available.Windows Server 2003 /// and Windows XP Professional x64 Edition: This value is not supported until Windows Server 2003 with SP1 and Windows XP with SP3. /// /// /// /// /// Future versions of Windows may support additional values for the Relationship member. /// public LOGICAL_PROCESSOR_RELATIONSHIP Relationship; /// The relationship union. public ProcessorRelationUnion RelationUnion; /// Union tied to the relationship. [StructLayout(LayoutKind.Explicit, Size = 16)] public struct ProcessorRelationUnion { /// This structure contains valid data only if the Relationship member is RelationProcessorCore. [FieldOffset(0)] public byte ProcessorCoreFlags; /// This structure contains valid data only if the Relationship member is RelationNumaNode. [FieldOffset(0)] public uint NumaNodeNumber; /// /// /// A CACHE_DESCRIPTOR structure that identifies the characteristics of a particular cache. There is one record /// returned for each cache reported. Some or all caches may not be reported, depending on the mechanism used by the /// processor to identify its caches. Therefore, do not assume the absence of any particular caches. Caches are not /// necessarily shared among logical processors. /// /// This structure contains valid data only if the Relationship member is RelationCache. /// /// Windows Server 2003: This member is not supported until Windows Server 2003 with SP1 and Windows XP Professional /// x64 Edition. /// /// [FieldOffset(0)] public CACHE_DESCRIPTOR Cache; } } /// /// /// Contains information about the relationships of logical processors and related hardware. The GetLogicalProcessorInformationEx /// function uses this structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_system_logical_processor_information_ex typedef struct // _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX { LOGICAL_PROCESSOR_RELATIONSHIP Relationship; DWORD Size; union { PROCESSOR_RELATIONSHIP // Processor; NUMA_NODE_RELATIONSHIP NumaNode; CACHE_RELATIONSHIP Cache; GROUP_RELATIONSHIP Group; } DUMMYUNIONNAME; } // SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX; [PInvokeData("winnt.h", MSDNShortId = "6ff16cda-c1dc-4d5c-ac60-756653cd6b07")] [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX { /// /// /// The type of relationship between the logical processors. This parameter can be one of the following /// LOGICAL_PROCESSOR_RELATIONSHIP values. /// /// /// /// Value /// Meaning /// /// /// RelationCache 2 /// The specified logical processors share a cache. The Cache member contains additional information. /// /// /// RelationGroup 4 /// The specified logical processors share a processor group. The Group member contains additional information. /// /// /// RelationNumaNode 1 /// The specified logical processors are part of the same NUMA node. The NumaNode member contains additional information. /// /// /// RelationProcessorCore 0 /// The specified logical processors share a single processor core. The Processor member contains additional information. /// /// /// RelationProcessorPackage 3 /// The specified logical processors share a physical package. The Processor member contains additional information. /// /// /// public LOGICAL_PROCESSOR_RELATIONSHIP Relationship; /// /// The size of the structure. /// public uint Size; /// The relationship union. public ProcessorRelationUnion RelationUnion; /// Union tied to the relationship. [StructLayout(LayoutKind.Explicit)] public struct ProcessorRelationUnion { /// /// A PROCESSOR_RELATIONSHIP structure that describes processor affinity. This structure contains valid data only if the /// Relationship member is RelationProcessorCore or RelationProcessorPackage. /// [FieldOffset(0)] public PROCESSOR_RELATIONSHIP Processor; /// /// A NUMA_NODE_RELATIONSHIP structure that describes a NUMA node. This structure contains valid data only if the /// Relationship member is RelationNumaNode. /// [FieldOffset(0)] public NUMA_NODE_RELATIONSHIP NumaNode; /// /// A CACHE_RELATIONSHIP structure that describes cache attributes. This structure contains valid data only if the /// Relationship member is RelationCache. /// [FieldOffset(0)] public CACHE_RELATIONSHIP Cache; /// /// A GROUP_RELATIONSHIP structure that contains information about the processor groups. This structure contains valid data /// only if the Relationship member is RelationGroup. /// [FieldOffset(0)] public GROUP_RELATIONSHIP Group; } } /// Used by GetProcessorSystemCycleTime. [PInvokeData("WinNT.h")] [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION { /// The cycle time for a processor. public ulong CycleTime; } } }