How to turnoff or restart your PC using a C Program

How to turnoff or restart your PC using a C Program

 Deepanshu Rajora

View (1541)

This article will help you to invoke system level commands and shutdown your pc using programs. Invoking system level commands will help you learn more about how your operating system works and helps you to create events in your system, this will also help you to automate tasks.

It won’t take more than a minute to code and compile it. Moreover a newbie C programmer who knows some basics in C program can understand this program.

If you want mastering in C programming, You may learn from a pro on your own schedule
 

C Program to shutdown your computer: This program turn off i.e shutdown your computer system. Firstly it will asks you to shutdown your computer if you press ‘y’ then your computer will shutdown in 30 seconds, system function of “stdlib.h” is used to run an executable file shutdown.exe which is present in C:WINDOWSsystem32 in Windows XP. You can use various options while executing shutdown.exe, you can use -t option to specify number of seconds after which shutdown occurs.

Syntax: shutdown -s -t x; here x is the number of seconds after which shutdown will occur.

By default shutdown occur after 30 seconds.To shutdown immediately you can write “shutdown -s -t 0”. If you wish to restart your computer then you can write “shutdown -r”.

C programming code for Windows XP

C programming code for Windows 7 and above

C programming code for Ubuntu Linux

You need to be logged in as root user for above program to execute otherwise you will get the message shutdown: Need to be root, now specifies that you want to shutdown immediately. ‘-P’ option specifies you want to power off your machine. You can specify minutes as:
shutdown -P “number of minutes”.

 If you like this Program and find this helpful, don't forget to like and share with your friends!

About the author

Most Read

The new kid in the block: Android Noughat

Google has been following a similar pattern with its Android naming process....

Watch Security Cams in the open using Google dorks

Are you aware that there is no such thing on the internet as, “Hiding in...

How to create Splash Screen in Android

Android splash screen are normally used to show user some kind of progress...

PHP vs ASP.Net (Championship)

Here we are about to start with the boxing match between two champions.One side...

Reasons that prove BIG DATA is the next Big thing!

According to analysts, the big data market has been predicted to be USD $50...
X
Register Here
 
By signing up , you agree to our Terms of Service and Privacy Policy.
 Login With
Facebook
Facebook
Google
Google
X
Log In Here
 
Remember me Forgot password?
 Login With
Facebook
Facebook
Google
Google
X
Reset Password
 
X

Confirmation Message

Yes No
X
Forgot Password
 
Do you want to Login ?