You might want to have a look at www.iomad.org. This is a "commercial" version/extension of Moodle. It has a licensing module which I think might do exactly what you are looking for.
General help
Limiting Enrollment
This discussion has been locked so you can no longer reply to it.