954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to make computer shutdown in C

how to make computer shutdown in C?which header do i have to include?

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

You need the windows header.

int main()
{
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;
    
    if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    {
        
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        if(AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
        {
            ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF|EWX_FORCE,0);
        }
    }
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

I don't have a Unix system, but try this and tell me whether it works:

#include <stdlib.h>

int main( )
{
    system( "shutdown" ) ;
    return 0 ;
}


For references see here and here .

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

no actualy i want that for windows....

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

Check my post again.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Is there anything written there, because I can't see anything at my side ?

Attachments untitled.JPG 27.55KB
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

lol....he was just pressing enter

So can you give me source?

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

You can try this . Haven't verified it but should work.

Just write the function, call it in main().

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

lol....he was just pressing enter

So can you give me source?


Don't you ever read the posts to your thread? :eek: I already gave you the win32 api function call for MS-Windows os. Just click the link I posted and you will get everything you need to know about that function. include to use it.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Check my post again please.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
Check my post again please.


It still looks blank in my browser window. Maybe someone needs to edit your post...

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

Hint

You need to hold down the left mouse button over the blank parts then drag the mouse down.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Heh..I knew that, just wanted to tell you that it is not a normal way of reading posts and many members will get confused...;)

BTW have fixed the code so that it can be read by each and every person.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

Heh..I knew that, just wanted to tell you that it is not a normal way of reading posts and many members will get confused...;)

BTW have fixed the code so that it can be read by each and every person.

Appears we need to have Ms. Dani add a new category to the Rules thread -- do not make hidden posts. I don't know how he did it, but than you ~S.O.S~ for fixing it up. :)

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I guess he used the [COLOUR=WHITE] tag.. I'm not sure why Daniweb even has this, since AFAIK, its not possible to change the background of posts (Probably a good thing...)

I imagine a few other colours on that chart would be pretty nasty to read aswell... Maybe that rule should be "No unreadable colours" :)

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 
I guess he used the [COLOUR=WHITE] tag.. I'm not sure why Daniweb even has this, since AFAIK, its not possible to change the background of posts (Probably a good thing...)


Yeah, I think he used the color white for posting, but don't know why play this prank...:(Appears we need to have Ms. Dani add a new category to the Rules thread -- do not make hidden posts. I don't know how he did it, but thank you ~S.O.S~ for fixing it up.
Yes it is a good idea to let Miss Dani know of it.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

I guess he used the [COLOUR=WHITE] tag.. I'm not sure why Daniweb even has this, since AFAIK, its not possible to change the background of posts (Probably a good thing...)

I imagine a few other colours on that chart would be pretty nasty to read aswell... Maybe that rule should be "No unreadable colours" :)


Haha, this used to happen a lot at Cprogramming. We often hid little messages in our post while it contained useful information, so it didn't look suspecting. The background wasn't white, so we looked in the CSS to retrieve the HTML color, and then used this to make parts of the post invisible. Finally the mods got mad at us, and we had to stop. :D

The only time white is visible is when it's within another kind of tag:this is some whiteI don't have a Unix system, but try this and tell me whether it works:
Your code usually won't work. Most Unix-based systems require you to use shutdown now or shutdown -t <em>seconds till shutdown</em> . And even with the correct syntax, shutdown is only made possible if the program is run with root privilages.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

unless of course you #include "im133e7hax0r.h" :)

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
Your code usually won't work. Most Unix-based systems require you to use shutdown now or shutdown -t <em>seconds till shutdown</em> . And even with the correct syntax, shutdown is only made possible if the program is run with root privilages.


I guess, you forgot to click on the links which I included with that post, which explains in detail the syntax of "shutdown" along with its usage. ;)

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You