Anyone could help me to find the code?
please.thx.

Recommended Answers

All 3 Replies

I think this is more easily done with the shell.

Hi there,

It's very simple to shutdown your PC using C program on Windows platform. Here is an example :

#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
char *q[40]={"shutdown -s -f -t 100"}; /* place any value you like at the place of 10
 value is in second so 100 sec = 1 min 40 sec*/
cout<<"SHUTDOWN TO THIS SYSTEM IS IN PROGRESS..";
system(*q);
getch();
exit(1);
}

and here you go.. Now execute the exe file created by your compiler. And your system will show you shutdown message.
To prevent shutdown follow this step:
Go to start -> Run -> Type: shutdown -a
it will abort the SHUTDOWN Process.

In the same way you can do it for a restart :

#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
char *q[40]={"shutdown -r -t 15"};
cout<<"RESTARTING COMPUTER IN 15 SECONDS";
system(*q);
exit(1);
getch();
}

I hope it would help you..

Regards
Surya

commented: Code full of bad practices, with no explanation of what's going on in there. Definitely -1 +0

I agree with cezar.elnazli comment "Code full of bad practices, with no explanation of what's going on in there. Definitely -1". But my dear friend this is not a big program or complicated enough to understand and I made it with in 5 minute and posted it on 6th minute when I look for this kind of post. I don't have that much time to put comment, cause I have other works too. May be it was my fault to come first to help some one especially with source code. I do comment my source code when it goes more than 50 lines. But let it be, may be it is a new lesson to me to have a negative reputation even in helping others. And yes I won't repeat this mistake again.

Regards
Surya

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.