To make certain modifications to system preferences, you first need to unlock the preference pane. Some of these changes are done on a system level and the command-line equivalent would need to be invoked as the root user (via setuid). However, running sudo has an expiration (typically 5 minutes) before needing to re-authenticate again; how do system preferences assert their "open lock" state?
What you are describing is the standard way, the Mac OS X do it. You have to do the following to get around the five minuts loop hole: Guide to lock system preference
It is assert by using plist files which I hold system times etc. or that is how it was done i Snow Leopard and older.
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.