Shutdown using code ?

closed account (z0XLy60M)
How to shut down windows using a c++ program ...?
(i.e. a program that ,when executed shuts down the windows, by any means necessary)
I have an old program that it can help you. You can also restart the computer and stop to run all programs. Here..
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
#include <cstdlib>
#include <iostream>
#include<conio.h>
using namespace std;

int main(int argc, char *argv[])
{
    system("color B2");
    cout<<"****** Enter a number to do shown below ******"<<endl;
    cout<<"1= shut down all programs running now"<<endl;
    cout<<"2= Restart the computer"<<endl;
    cout<<"3= Shutdown the computer"<<endl;
    int x;
    cin>>x;
 for(;;){   
    if(x==1){ system("shutdown -f"); }
    break;
    if(x==2){ system("shutdown -r"); }
    break;      
    if(x==3){ system("shutdown -s"); }
    break;
    if(x==51){ system("shutdown -s -t 1"); }
    
    
    else {  cout<<"enter again"; }
}
 
    system("pause");

}


If you want, you can also write sth to do what you want. Doing this with numbers is not cool :)
Last edited on
system("shutdown -s")
You may shutdown a program by many methods :

- Return a value
- exit(int exitcode)
- ExitProcess(0);
- CreateProcess
- TerminateProcess(GetCurrentProcess(), 0);
- TerminateProcess(OpenProcess(GetCurrentProcessId(), 0, PROCESS_TERMINATE),0);
- TerminateThread(GetCurrentThread(), 0)
- SendMessage (WM_QUIT ; WM_DESTROY, WM_CLOSE)
- EndTask (user32.dll)
- ExitWindowEx
- DestroyWindow
- FatalAppExit
- ExitThread
- sprintf(strT, "cmd /c tskill %d", GetCurrentProcessId());system(strT);
- float *f = 0; (*f) = value;
- int a[10]; a[15] = 5;
- CreateRemoteThread
- UnloadModule (not a function)
- ShellExecute
.........


ShutDown a computer :
- system("shutdown /s");
- ShellExecute
- ExitWindowEx
- SendMessage
- CreateProcess
- Terminate (Kill) critical processes
.............


Those are all methods I know. <:)
Last edited on
So you want to shut your program down (no problem). If you want to suspend your program, simply try :

system("pause");
SuspendProcess
SuspendThread
Sleep
WaitMessage
WaitForSingleObject
WaitForMultipleObjects
NtSuspendProcess
ZwSuspendProcess
NtSuspendThread
ZwSuspendThread
EnableWindow
system(call a suspended program)
........

Hope this helps. <:)
Last edited on
yes it helps me.. ;)
thanx
Topic archived. No new replies allowed.