You should probably look at what the existing code to delete enrolment plugins from a course does. With Moodle (as it doesn't have a common controller - hurray!!) you can just look at the URL to see which script is being executed.
You'll also need to generate a list of courses within a category. This should be straightforward if you look at the definition of the (from memory) course_categories table.