Search code examples
clicensinglicense-key

How to get laptop Serial in C


Hi I'm trying to make a security feature for my C Project, so that if someone steals it, it becomes useless. It works as following: The main function only runs if the comparison of my macbook's Serial to an encrypted one is 1.

The Problem is that I cannot get the system info in the program.

When I do:

int main ()
{ i=0;  

if (strcmp(system("system_profiler SPHardwareDataType | grep \"Serial Number\""), 
                  "Serial Number (system): W80314GJATP"));

{
 bla
 bla 
 bla
}

else {for(i=0;i<100;i++)
         {printf("Unauthorized Computer");
     }

 return 1;
}

It only prints info to stdout. Is there a way to do that comparison?


Best Regards


Solution

  • system() does not return a char pointer, it returns the exit code (an int) from command that was run. You could use popen() to run a command. popen() will return a FILE* that you can read from (it is from the program's stdout). You can then read and parse the program output accordingly.