windows 如何在没有 WMI 的情况下获得唯一的机器签名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/872385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get unique machine signature without WMI?
提问by Hemant
I know that a questionhas already been asked about generating a unique ID for a machine but my question is slightly different.
我知道,一个问题已经被问生成一个机器一个唯一的ID,但我的问题是稍有不同。
I want to know whether there are any other methods (API calls?) to get hardware information and NOT use WMI. I understand from MSDNthat WMI is introduced in Win2000 so it doesnt seem to be available in Win98. I have an application that has to run even on Win98 (I know it sucks but what can you do?) and still get hold of hardware information.
我想知道是否有任何其他方法(API 调用?)来获取硬件信息而不使用 WMI。我从MSDN了解到 WMI 是在 Win2000 中引入的,所以它在 Win98 中似乎不可用。我有一个应用程序,它甚至必须在 Win98 上运行(我知道它很糟糕,但你能做什么?)并且仍然可以获取硬件信息。
采纳答案by Robert Venables
I've done this several times for licensing projects. For the hard drive serial number use:
我已经多次为许可项目这样做了。对于硬盘序列号,请使用:
private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32 VolumeSerialNumber, ref UInt32 MaximumComponentLength, ref UInt32 FileSystemFlags, StringBuilder FileSystemNameBuffer, UInt32 FileSystemNameSize);
Use the VolumeSerialNumber
that is returned by the function.
使用VolumeSerialNumber
函数返回的 。
Also, you may have thought about using the Windows Product ID (Located at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
). Be careful, a large number of Windows XP users have pirated copies and share the same product keys.
此外,您可能已经考虑过使用 Windows 产品 ID(位于HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
)。请注意,大量 Windows XP 用户拥有盗版副本并共享相同的产品密钥。
回答by Konstantinos
You can combine different hardware information in order to create a unique key.
您可以组合不同的硬件信息以创建唯一的密钥。
For example, CPU ID, MAC address etc etc. You retrieve them, combine them, encrypt them and you have a unique representation of the hardware setup of this machine.
例如,CPU ID、MAC 地址等。您检索它们、组合它们、加密它们,并且您拥有这台机器硬件设置的唯一表示。
Try googling about the subject: how to read hardware information.
尝试使用谷歌搜索这个主题:如何阅读硬件信息。
From what I can see there is a very useful post in CodeProject: How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...).
从我所看到的 CodeProject 中有一个非常有用的帖子:How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information, ...)。
回答by TheSoftwareJedi
Look through the WinAPI's kernel32 and user32 library. It has all sorts of goodies like EnumDisplayDevices
, GetLogicalDrives
, GlobalMemoryStatus
, GetVolumeInformation
, etc, etc. I Like to use PInvoketo browse the API since it gives me the C# wrapper code - but MSDN will have it all as well in the Windows SDK.
查看 WinAPI 的 kernel32 和 user32 库。它有各种各样的好东西,如EnumDisplayDevices
、GetLogicalDrives
、GlobalMemoryStatus
、GetVolumeInformation
等。我喜欢使用PInvoke来浏览 API,因为它为我提供了 C# 包装器代码 - 但 MSDN 也将在 Windows SDK 中提供所有这些。
@novatrust's answer regarding the hard drive serial is a good one - but can be combined with more. I've provided the GetVolumeInformation
API link to pinvoke above, but a simple Google should work as well.
@novatrust 关于硬盘序列号的回答很好 - 但可以结合更多。我已经提供了GetVolumeInformation
上面 pinvoke的API 链接,但是一个简单的 Google 也应该可以工作。