System preferences administrative privileges

Does anyone know how to alter a system preference if it is locked? For instance, I may want to change something in date and time. However it may be locked. I want to be able to unlock it, make my change, then lock it. Better yet, I’d like to be able to make the change without the locking and unlocking, kind of like using ‘with administrative privileges’ when creating a shell script. I am using system events to change alter the system preferences and it works just fine. I would just like to be able to test whether the preferences are locked or not, and if they are, unlock them and make the change.