建议楼主找一下win32 api的相关信息。
摘自msdn:
DnsHostnameToComputerName Converts a DNS name to a NetBIOS name.
EnumSystemFirmwareTables Enumerates all system firmware tables of the specified type.
ExpandEnvironmentStrings Replaces environment-variable strings with their defined values.
GetComputerName Retrieves the NetBIOS name of the local computer.
GetComputerNameEx Retrieves the NetBIOS or DNS name of the local computer.
GetComputerObjectName Retrieves the local computer's name in a specified format.
GetCurrentHwProfile Retrieves the current hardware profile for the local computer.
GetFirmwareEnvironmentVariable Retrieves the value of the specified firmware environment variable from NVRAM.
GetKeyboardType Retrieves information about the current keyboard.
GetNativeSystemInfo Retrieves information about the current system for an application running under WOW64.
GetSysColor Retrieves the current color of a display element.
GetSystemDirectory Retrieves the path of the system directory.
GetSystemFirmwareTable Retrieves the specified firmware table from the firmware table provider.
GetSystemFileCacheSize Retrieves the current size limits for the working set of the system cache.
GetSystemInfo Retrieves information about the current system.
GetSystemMetrics Retrieves system metrics and configuration settings.
GetSystemRegistryQuota Retrieves the current size of the registry and the maximum size that the registry is allowed to attain on the system.
GetSystemWindowsDirectory Retrieves the path of the shared Windows directory on a multi-user system.
GetSystemWow64Directory Retrieves the path of the system directory used by WOW64.
GetUserName Retrieves the user name of the current thread.
GetUserNameEx Retrieves the name of the user or other security principal associated with the calling thread. You can specify the format of the returned name.
GetVersion Retrieves the version number of the operating system.
GetVersionEx Retrieves the version of the current operating system.
GetWindowsDirectory Retrieves the path of the Windows directory.
IsProcessorFeaturePresent Determines whether a processor feature is supported by the current computer.
IsWow64Message Determines whether the last message read from the queue of the current process originated from a WOW64 process.
IsWow64Process Determines whether a process is running under WOW64.
NtQuerySystemInformation Retrieves various kinds of system information.
SetComputerName Stores a new NetBIOS name for the local computer.
SetComputerNameEx Stores a new NetBIOS or DNS name for the local computer.
SetFirmwareEnvironmentVariable Sets the value of the specified firmware environment variable in NVRAM.
SetSysColors Sets the colors for one or more display elements.
SetSystemFileCacheSize Limits the size of the working set for the file system cache.
SystemParametersInfo Queries or sets system-wide parameters.
TranslateName Converts a directory service object name from one format to another.
VerifyVersionInfo Compares a set of version requirements to the values for the current operating system.
VerSetConditionMask Builds the condition mask for the VerifyVersionInfo function.
Wow64DisableWow64FsRedirection Disables file system redirection for the calling thread.
Wow64EnableWow64FsRedirection Enables or disables file system redirection for the calling thread.
在.net环境下(用VC#描述)获取机器的硬件信息,要用到一个类库(System.Management.dll),在解决方案资源管理器中添加System.Management 即可
我们可以将该程序编译成.dll文件,便于以后调用;
在程序代码中进行引用 using System.Management;
具体 代码为:
1.获取机器名:
public string GetHostName()
{
return System.Net.Dns.GetHostName();
}
2.获取CPU编号
public string GetCpuId()
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
String strCpuID = null ;
foreach( ManagementObject mo in moc )
{
strCpuID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strCpuID;
}
3.获取主硬盘编号
public string GetMainHardDiskId()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
String strHardDiskID = null ;
foreach(ManagementObject mo in searcher.Get())
{
strHardDiskID = mo["SerialNumber"].ToString().Trim();
break;
}
return strHardDiskID ;
}
4.获取bios和mac地址,这个有点复杂,需要用到NETAPI32.DLL