handle pc shutdown hibernate in c/c++ code example

Example: handle pc shutdown hibernate in c/c++

if (isCommand(arithTrig, "sleep")) {
		command = true;
		puts(" ");
		ShellExecute(NULL, _T("runas"), _T("C:\\WINDOWS\\system32\\cmd.exe"), _T("/C \"powercfg -hibernate off\""), NULL, SW_SHOW);
		Sleep(5000);
		system("C:\\WINDOWS\\System32\\Rundll32.exe powrprof.dll,SetSuspendState Sleep");
	}
	if (isCommand(arithTrig, "lock")) {
		command = true;
		puts(" ");
		system("C:\\WINDOWS\\System32\\Rundll32.exe User32.dll,LockWorkStation");
	}
	if (isCommand(arithTrig, "hibernate")) {
		command = true;
		puts(" ");
		ShellExecute(NULL, _T("runas"), _T("C:\\WINDOWS\\system32\\cmd.exe"), _T("/C \"powercfg -hibernate on\""), NULL, SW_SHOW);
		Sleep(5000);
		system("C:\\WINDOWS\\System32\\rundll32.exe PowrProf.dll,SetSuspendState Hibernate");
	}
	if (isCommand(arithTrig, "shutdown")) {
		continu = 0;
		command = true;
		if (IsPreviousToWindowsVista()) {
			system("C:\\WINDOWS\\System32\\shutdown -s");
		}
		else {
			system("C:\\WINDOWS\\System32\\shutdown /s");
		}
	}
	if (isCommand(arithTrig, "shutdownnow")) {
		continu = 0;
		command = true;
		if (IsPreviousToWindowsVista()) {
			system("C:\\WINDOWS\\System32\\shutdown -s -t 0");
		}
		else {
			system("C:\\WINDOWS\\System32\\shutdown /s /t 0");
		}
	}
	if (isCommand(arithTrig, "restartpc")) {
		continu = 0;
		command = true;
		if (IsPreviousToWindowsVista()) {
			system("C:\\WINDOWS\\System32\\shutdown -r");
		}
		else {
			system("C:\\WINDOWS\\System32\\shutdown /r");
		}
	}
	if (isCommand(arithTrig, "restartpcnow")) {
		continu = 0;
		command = true;
		if (IsPreviousToWindowsVista()) {
			system("C:\\WINDOWS\\System32\\shutdown -r -t 0");
		}
		else {
			system("C:\\WINDOWS\\System32\\shutdown /r /t 0");
		}
	}
    
    if (isCommand(arithTrig, "logoff")) {
		continu = 0;
		command = true;
		if (IsPreviousToWindowsVista()) {
			system("C:\\WINDOWS\\System32\\shutdown -l");
		}
		else {
			system("C:\\WINDOWS\\System32\\shutdown /l");
		}
	}

Tags:

Cpp Example