Download: LockDock
It works by using calling the following shell commands (via applescript)
defaults write com.apple.Dock contents-immutable -bool yes
defaults write com.apple.Dock size-immutable -bool yes
defaults write com.apple.Dock position-immutable -bool yes
killall Dock
(or replace yes by false for unlocking)
Send me a message if you want the XCode project...