What C++ commands are used to shutdown and restart PC?

Status
Not open for further replies.

ehsanelahimirza

Full Member level 6
Joined
Feb 24, 2006
Messages
334
Helped
28
Reputation
56
Reaction score
7
Trophy points
1,298
Activity points
3,570
shutdown restar in c++

hi all

plz tell me what commands r used to shutdown or restart a pc in c++

plz give me the syntax with some example
 

shutdown restar in c++

you can use the next:

Code:
 system ( "shutdown -s" )
for shutdown pc and
Code:
 system ( "shutdown -r")
for restarting a pc

also you can specify the time for shutdown pc:
Code:
 system ( "shutdown -s -t 3600" )
this code will shutdown pc after 1h

here is an example:
Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    system("shutdown -s -t 3600");
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
this will shutdown pc after 1h
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…