get unique machine id
get unique machine id
I want to get unique unchangeable Machine id Like Processor serial number of the computer for distribute a software with out copying.
I tried with processor serial number and hard disk serial number that all are changing after formatting and reinstalling the windows.
Any idea how i can get an unchangeable serial number of a computer?
Answer by Blindy for get unique machine id
edit: I just saw you meant in c#. Here is a better way with unmanaged code:
ManagementClass oMClass = new ManagementClass ("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection colMObj = oMCLass.GetInstances(); foreach(ManagementObject objMO in colMObj) Console.WriteLine(objMO["MacAddress"].ToString());
Answer by Laurent Etiemble for get unique machine id
Check out this article. It is very exhaustive and you will find how to extract various hardware information.
Quote from the article:
To get hardware information, you need to create an object of ManagementObjectSearcher class.
using System.Management; ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key); foreach (ManagementObject share in searcher.Get()) { // Some Codes ... }
The Key on the code above, is a variable that is replaced with appropriate data. For example, to get the information of the CPU, you have to replace the Key with Win32_Processor.
Answer by Heinzi for get unique machine id
I second Blindy's suggestion to use the MAC address of the (first?) network adapter. Yes, the MAC address can be spoofed, but this has side effects (you don't want two PCs with the same MAC address in the same network), and it's something that "your average pirate" won't do just to be able to use your software. Considering that there's no 100% solution against software piracy, the MAC address is a good compromise, IMO.
Note, however, that the address will change when the user adds, replaces or removes a network card (or replaces his old PC altogether), so be prepared to help your customers and give them a new key when they change their hardware configuration.
Answer by Oliver for get unique machine id
If you need a unique ID, you must first decide what do you mean with unique. If you like to use it for a copy protection mechanism than take something simple, cause if someone wants to use your software he can break your protection. In case of a unique hardware id, just think about VMware and you'll see you can spoof anything or someone can start to tamper your software.
So there is not much you can take from a pc as uniqueness over it's whole lifetime. If you need something like that you should start a search for a USB Dongle which you can send to your customers.
If you just need some less harder uniqueness you could take the MAC address, the OS serial number or the domain and username, but all of them are forgeable. But if your main goal is to lock out people you won't sell anything because no one wants to use your software because it is so hard to install or to move from one pc to another (this will happen quite often).
So in a first step, make it easy, take something simple which is not as easy to spoof in your target group (e.g. domain and usernames can't be good spoofed by enterprise customers, cause their pcs are running in a bigger environment with policies, etc.) and just forget about the others.
Maybe you can lock them out but that doesn't mean they're going to buy your software, they just don't use it anymore. But how many potential customers are not willing to pay cause you made it so complicated to use your program?
Answer by Duncan Bayne for get unique machine id
I'd stay well away from use MAC addresses. On some hardware the MAC address can change when you reboot. We learned quite early during our research not to rely on it.
Take a look at the article Developing for Software Protection and Licensing which has some pointers on how to design & implement apps to reduce piracy.
Obligatory disclaimer & plug: the company I co-founded produces the OffByZero Cobalt licensing solution. So it probably won't surprise you to hear that I recommend outsourcing your licensing, & focusing on your core competencies.
Answer by PRR for get unique machine id
You can use WMI Code creator. I guess you can have a combination of "keys" (processorid,mac and software generated key).
using System.Management; using System.Windows.Forms; try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_Processor instance"); Console.WriteLine("-----------------------------------"); Console.WriteLine("Architecture: {0}", queryObj["Architecture"]); Console.WriteLine("Caption: {0}", queryObj["Caption"]); Console.WriteLine("Family: {0}", queryObj["Family"]); Console.WriteLine("ProcessorId: {0}", queryObj["ProcessorId"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); }
Retrieving Hardware Identifiers in C# with WMI by Peter Bromberg
Answer by TheGateKeeper for get unique machine id
You can try getting some info from the bios. This will still be valid after a format.
Answer by Raj for get unique machine id
Yes, We could get a code which is combination of Physical Address, Unique Drive ID, Hard Drive ID (Volume Serial), CPU ID and BIOS ID. Example (Full example):
//Main physical hard drive ID private static string diskId() { return identifier("Win32_DiskDrive", "Model") + identifier("Win32_DiskDrive", "Manufacturer") + identifier("Win32_DiskDrive", "Signature") + identifier("Win32_DiskDrive", "TotalHeads"); } //Motherboard ID private static string baseId() { return identifier("Win32_BaseBoard", "Model") + identifier("Win32_BaseBoard", "Manufacturer") + identifier("Win32_BaseBoard", "Name") + identifier("Win32_BaseBoard", "SerialNumber"); }
Answer by Nik Shev for get unique machine id
You should not use MAC, its bad way. Because some OS just changeing it every day. My expirience : Tools.CpuID.ProcessorId() + volumeSerial;
string volumeSerial = ""; try { ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""C:"""); dsk.Get(); volumeSerial = dsk["VolumeSerialNumber"].ToString(); } catch { try { ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""D:"""); dsk.Get(); volumeSerial = dsk["VolumeSerialNumber"].ToString(); } catch { File.WriteAllText("disk.mising","need C or D"); Environment.Exit(0); } } public class CpuID { [DllImport("user32", EntryPoint = "CallWindowProcW", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)] private static extern IntPtr CallWindowProcW([In] byte[] bytes, IntPtr hWnd, int msg, [In, Out] byte[] wParam, IntPtr lParam); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool VirtualProtect([In] byte[] bytes, IntPtr size, int newProtect, out int oldProtect); const int PAGE_EXECUTE_READWRITE = 0x40; public static string ProcessorId() { byte[] sn = new byte[8]; if (!ExecuteCode(ref sn)) return "ND"; return string.Format("{0}{1}", BitConverter.ToUInt32(sn, 4).ToString("X8"), BitConverter.ToUInt32(sn, 0).ToString("X8")); } private static bool ExecuteCode(ref byte[] result) { int num; /* The opcodes below implement a C function with the signature: * __stdcall CpuIdWindowProc(hWnd, Msg, wParam, lParam); * with wParam interpreted as an 8 byte unsigned character buffer. * */ byte[] code_x86 = new byte[] { 0x55, /* push ebp */ 0x89, 0xe5, /* mov ebp, esp */ 0x57, /* push edi */ 0x8b, 0x7d, 0x10, /* mov edi, [ebp+0x10] */ 0x6a, 0x01, /* push 0x1 */ 0x58, /* pop eax */ 0x53, /* push ebx */ 0x0f, 0xa2, /* cpuid */ 0x89, 0x07, /* mov [edi], eax */ 0x89, 0x57, 0x04, /* mov [edi+0x4], edx */ 0x5b, /* pop ebx */ 0x5f, /* pop edi */ 0x89, 0xec, /* mov esp, ebp */ 0x5d, /* pop ebp */ 0xc2, 0x10, 0x00, /* ret 0x10 */ }; byte[] code_x64 = new byte[] { 0x53, /* push rbx */ 0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00, /* mov rax, 0x1 */ 0x0f, 0xa2, /* cpuid */ 0x41, 0x89, 0x00, /* mov [r8], eax */ 0x41, 0x89, 0x50, 0x04, /* mov [r8+0x4], edx */ 0x5b, /* pop rbx */ 0xc3, /* ret */ }; byte[] code; if (IsX64Process()) code = code_x64; else code = code_x86; IntPtr ptr = new IntPtr(code.Length); if (!VirtualProtect(code, ptr, PAGE_EXECUTE_READWRITE, out num)) Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); ptr = new IntPtr(result.Length); try { return (CallWindowProcW(code, IntPtr.Zero, 0, result, ptr) != IntPtr.Zero); } catch { System.Windows.Forms.MessageBox.Show("?????? ??????????"); return false; } } private static bool IsX64Process() { return IntPtr.Size == 8; } }
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment