Yes you can, and you dont even have to program for that ;)
You can configure the permissions of "general" group. This is where "anonymous user" is linked to.
There you'll find several entries about reading, posting, anonymous posting, ... you can give anonymous users the rights you want them to have
The entry you may look for in special is:
Anonymous Posts
Deny anonymous posts
There you have to mark all forums where the anonymous user will not be allowed to write to ...
I hope I could help you
[originally posted on jforum.net by Sid]