Unless you're dealing with some pretty sophisticated stuff (like graphics where you can imbed detectable, hidden signatures), you can't tell. Even then, if you give out the source code, any kind of detection methods can be disabled. On the other hand, if you create only DLLs or things like ActiveX controls, then you can control things a little more by encoding call to home functionality where they report their usage to a server and then you can monitor the incoming data.

Here's the thing, though... why do you care? If it's so important that commercial apps don't use your code, don't give it out at all. The world does not consist only of college students and Microsoft... there are a lot of other folks out there that blur the line between commercial and non-commercial. If you're going to take a stand, you need to be prepared to deal with a ton of headaches. Unless you're talking about some extraordinarily valuable piece of code, I don't see how it could be worth it.