The
ExitWindowsEx() function should do it. Make sure you include windows.h
For dwReason, you need to enter a System Shutdown Reason code. The full list is over
here. So, for example, this should log off the user with "Application Issue" as the reason. (WARNING: UNTESTED)
#include <windows.h>
int main() {
ExitWindowsEx(EWX_LOGOFF, SHTDN_REASON_MAJOR_APPLICATION);
}