How to write a program to shutdown a system in C/C++

 How to shut down the computer in Linux and/or Windows?

The idea is to use system() in C language. This function is used to call operating system commands
from a C program.

Linux OS:

// C program to shutdown in Linux
#include <stdio.h>
#include <stdlib.h>

int main()
{
// Running Linux OS command using system
system("shutdown -P now");
return 0;
}

 
Windows OS:
                                  Shutdown/ Logoff/ Restart a Windows OS

We will use system() in <stdlib.h> to perform system operations with the help of C programs.To perform any of the above system operations, we will code as follows:

#include <stdio.h> #include <stdlib.h> int main() { system("c:\\windows\\system32\\shutdown /i"); return 0; }


The argument to the system function is the path to OS and /i is one of the entities from the vast options available to us. To view the options, we run cmd and type:

                      C:\Users\User>shutdown
To perform different operations, we just replace the last “/path” in system() argument.The common operations are:
                                                     Shutdown
          system("c:\\windows\\system32\\shutdown /s");
                                                   Restart 
        system("c:\\windows\\system32\\shutdown /r");
                                                Logoff
      system("c:\\windows\\system32\\shutdown /l");

Comments

Popular posts from this blog

proassignment help backlink data index 41

Programming shark backlink data index 67

programming shark backink data index 31