You may license what end-user will do with the code however you want. I think you have been misinformed. This cannot legally be done in the US under copyright law (except, since one year ago, in programs with license managers whose source is not available).
If you could do impose such restrictions, they would make the program non-free.