If you’re working on a remote computer via Screen Sharing and accidentally lock yourself out you may be able to re-enable screen sharing via SSH.
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all
See this article for reference: http://support.apple.com/kb/HT2370