-
September 7th, 2005, 07:31 AM
#1
Can I identify a particular computer from a program?
I am working on a school project on C++. I want my program to identify a particular computer if run on it. Is there some way I can do that?
A friend told me about using chipset id. Is it unique? If so is there some way I can read that from within the program?
-
September 7th, 2005, 07:46 AM
#2
Re: Can I identify a particular computer from a program?
The operating system usually knows what the hardware architecture is, so the easiest way is query the OS for this information.
-
September 7th, 2005, 10:03 AM
#3
Re: Can I identify a particular computer from a program?
Originally Posted by Ashik729
I am working on a school project on C++. I want my program to identify a particular computer if run on it. Is there some way I can do that?
A friend told me about using chipset id. Is it unique? If so is there some way I can read that from within the program?
What do you mean by identification? You get information descrybing computer from outside or using the same programm. You can check if computer for given configuration is changed. You maybe know computer's host name and want to detect once your programm is run on it?
"Programs must be written for people to read, and only incidentally for machines to execute."
-
September 7th, 2005, 11:51 PM
#4
Re: Can I identify a particular computer from a program?
I wanted to distinguish between two systems if the program is run on them.
I want something that will be unique for each system.
-
September 8th, 2005, 01:15 PM
#5
Re: Can I identify a particular computer from a program?
Originally Posted by Ashik729
I wanted to distinguish between two systems if the program is run on them.
I want something that will be unique for each system.
And you want this distinction to be made at runtime? Generally, one would make this distinction at compile time, using preprocessor directives:
Code:
#ifdef _WIN32_ // or something like that
#define function(arg) windows_specific_function(arg)
#elif defined _UNIX_ // or something like that
#define function(arg) unix_specific_function(arg)
#else
#define function(arg) some_other_function(arg)
#endif
Old Unix programmers never die, they just mv to /dev/null
-
September 9th, 2005, 11:04 AM
#6
Re: Can I identify a particular computer from a program?
Originally Posted by Ashik729
I am working on a school project on C++. I want my program to identify a particular computer if run on it. Is there some way I can do that?
A friend told me about using chipset id. Is it unique? If so is there some way I can read that from within the program?
I presume you are working under Windows.
You can get the chipset ID with the following script:
Code:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
Wscript.Echo "Processor ID: " & objItem.ProcessorId
Next
This script comes from a collection of scripts at http://www.microsoft.com/technet/scr.../hwbavb03.mspx
Copy this code in a file whose name will be e.g., get_cpuid.vbs. You can launch it from Windows Explorer, with the usual doule-click or single-click. You can also launch it from the command prompt with "cscript.exe get_cpuid.vbs".
I have found no API retrieving the cpuid. Instead, you can embed a few lines of assembly code in a VC++ source code:
Code:
UINT64 get_cpuid(void)
{
DWORD dwStandard = 0;
DWORD dwFeature = 0;
_asm {
mov eax, 1
cpuid
mov dwStandard, eax
mov dwFeature, edx
}
return( ((UINT64)(dwFeature) << 32) | ((UINT64)(dwStandard)));
}
I don't know how this code is working on multi-processor machines.
More information about CPUID at http://www.paradicesoftware.com/specs/cpuid/ (The CPUID Guide) and http://www.sandpile.org/ia32/cpuid.htm (Technical specifications)
I have thought of others solutions:
- Get the NIC (network interface card) ID. But computers may have zero, one or several NIC per PC, and they may be replaced more often than CPUs, therefore, the CPU ID may be a better option.
- Get the MAC (Media Access Control) address. But this may not be more interesting than the CPU ID.
- Get the name of the computer with:
Code:
int get_computer_name(BYTE *computer_name, DWORD *computer_name_lg)
{
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName",
0, KEY_QUERY_VALUE, &hKey ) != ERROR_SUCCESS)
return FALSE;
if (RegQueryValueEx(hKey, "ComputerName", NULL, NULL,
(LPBYTE) computer_name,
(LPDWORD) computer_name_lg) != ERROR_SUCCESS) {
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
...
BYTE name[250] = "Default name";
DWORD name_lg = 250;
if (get_computer_name(name, &name_lg) == TRUE) {
...
}
This is working well with my Windows ME computer and with my Windows XP computer. But, unfortunately there is no guarantee that computer names will be unique. It depends on the name that was assigned to them when Windows was installed.
-
October 7th, 2005, 08:50 AM
#7
Re: Can I identify a particular computer from a program?
I tried the chipset id and it worked. but i want to do the same thing under linux. how can i get this to work in linux?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|