Search This Blog

C Program to Schedule a Shutdown - How to Schedule Shutdown in C

You can schedule shutdown in Windows or Linux using C program. We will see how to schedule a shutdown using a c program. To schedule a shutdown in Windows, we execute the Windows command shutdown /s /t sec (where sec is time delay before shutdown in seconds). In Linux, we execute the command shutdown -h +600.  The c programs to schedule a shutdown in Windows and Linux are given separately.

C Program to Shutdown Computer - How to Shutdown Computer Using C Code

Computer can be shutdown using c program. But the commands are different in Windows and Linux. The system() function in c can be used to execute system commands ( Windows command or Linux command ). To shutdown the computer using c program, we execute the appropriate shutdown command using the system() function.

How to Execute Windows Commands in C

You may have used Windows commands like ipconfig, netstat, type, set, mkdir, cd etc in cmd (DOS Prompt or Command Prompt). You can execute these commands from a C program. This post will tell you how to execute Windows commands (cmd commands) from c program. To execute different Windows commands, you can use the system() function c language. The system() function is used to invoke command processor to execute a given command. The command which is to be executed is passed as argument to the function. An example c program with system() function is shown below.

C Program to Logoff or Signout From Windows

You can logoff (also called logout or sign out) from a windows computer using c program. This can be done by executing a command. You just have to execute the command shutdown /l which executes shutdown.exe with command line parameter /l to force logout from Windows. The system() function in c can be used to execute any system commands. Therefore, the following simple c program when executed, will logout you from Windows instantly.


#include<stdio.h>
void main()
{
system("shutdown /l");
}

Digital Clock C Program

This is a c program to display a digital clock showing correct time. It reads time at 1 second interval and displays it on the screen. To know how to get date and time in C, see this post: How to Get Time and Date in C - C Program to Read and Display Time and Date


#include<stdio.h>
#include<graphics.h>
#include<time.h>
int gd=DETECT,gm,x,y;

void main()
{
time_t now;
struct tm *timeinfo;
initgraph(&gd,&gm,"..\\BGI\\");
x=getmaxx()/2-80;
y=getmaxy()/2-20;

while(!kbhit())
 {
 time(&now);
 timeinfo=localtime(&now);
 printf("%2d : %2d : %2d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
 delay(1000);
 cleardevice();
 }
getch();
}