I think there are several options:
1) Grab the token from the user you want to logoff, then user createprocessasuser. This process uses ExitWindows(Ex) to logoff.
2) Providing Terminal Server (eg Windows XP Pro) is running you can use the Terminal Server
API to logoff a specific session, which would probably be the console session (use WTSGetActiveConsoleSessionId to obtain sessionid).
3) Maybe WTS_WSD_LOGOFF as Chris suggested is a good solution for you (according to docs you cannot remote logon after, but im not sure this is true for workstation also).
If a restart is ok you can offcourse use Terminal Server Shutdown function.