Yes, it's a tricky problem. Since a PC is nothing but a bunch of components, any one of which can be swapped out, how do you key something to a given computer? What defines the computer?
Windows itself uses a set of 10 or so items that it looks at. You can change some of those things, but once too much changes, you have to reactivate Windows.
Security is actually a big problem, not easily solved. That's why there are companies that specialize in this arena and will license their solutions for use in your application. And such stuff generally is not cheap (or rather, the cheap solutions tend to work poorly, and generally aren't worth the money).