shutdown program

Apr 14, 2013 at 9:56am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <iostream>

using namespace std;

int main ()
{
    int actionType;
    int seconds;
    cout << "What would you like to do?" << endl;
    cout << "1 = shutdown; 2 = hibernate" << endl;
    cin >> actionType;
    if (actionType != 1 || actionType != 2)
    {
        cout << "Invalid action ID" << endl;
        cout << "Please retype action ID" << endl;
        cin >> actionType;
    }
    cout << "Seconds until action: ";
    cin >> seconds;
    if ((MessageBox(NULL, "Are you sure?", "Confirm", MB_OKCANCEL)) == MB_OK)
    {
        HWND hWnd = GetConsoleWindow();
        ShowWindow(hWnd, SW_HIDE);
        Sleep(seconds * 1000);
        if (actionType == 1)
        {
            system("shutdown -s -f -t 10");
        }
        else if (actionType == 2)
        {
            system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0");
        }
    }
    return 0;
}


When I compile it it doesn't shout at me but when I run it it always displays the "Invalid action ID" the first time I enter either 1 or 2 and then works up until the
1
2
3
4
5
6
7
8
if (actionType == 1)
        {
            system("shutdown -s -f -t 10");
        }
        else if (actionType == 2)
        {
            system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0");
        }

meaning that it doesn't do anything. It will just sit there and look defiantly at me.
Apr 14, 2013 at 1:21pm
The first problem is you need to change
if (actionType != 1 || actionType != 2)
to
if (actionType != 1 && actionType != 2)

Apr 14, 2013 at 3:01pm
Alrighty, that solved the first problem, thanks for the info, also replaced the if with while but still... why doesn't it shut down the PC?
Topic archived. No new replies allowed.