For Windows you can Code: #include <windows.h> void adjusttoken() { HANDLE hToken; TOKEN_PRIVILEGES tkp; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)); LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); if (GetLastError() != ERROR_SUCCESS) { MessageBox(NULL,"Cannot gain appropriate permission","Shutdown error",0); } } int main() { adjusttoken(); /* You will probably need this */ ExitWindowsEx(EWX_POWEROFF|EWX_FORCE,0); }
Code: #include <stdio.h> int main(void) { system("SHUTDOWN -s"); return 0; } This will shutdown Windows XP when run.
hi......... #include<windows.h> main() { ExitWindowsEx(EWX_SHUTDOWN,EWX_FORCEIFHUNG); //check this link http://msdn2.microsoft.com/en-US/library/ms893047.aspx }