how to make computer shutdown in C?which header do i have to include?
jan1024188 7
Posting Whiz in Training
Recommended Answers
Jump to PostYou 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); } } }
Jump to PostI don't have a Unix system, but try this and tell me whether it works:
#include <stdlib.h> int main( ) { system( "shutdown" ) ; return 0 ; }
Jump to PostMS-Windows -- InitiateSystemShutdown()
Jump to PostCheck my post again.
Jump to PostIs there anything written there, because I can't see anything at my side ?
All 19 Replies
iamthwee
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
Ancient Dragon 5,243
Achieved Level 70 Team Colleague Featured Poster
jan1024188 7
Posting Whiz in Training
iamthwee
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
jan1024188 7
Posting Whiz in Training
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
Ancient Dragon 5,243
Achieved Level 70 Team Colleague Featured Poster
iamthwee
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
iamthwee
Ancient Dragon
commented:
stop that silly madness -2
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
Ancient Dragon 5,243
Achieved Level 70 Team Colleague Featured Poster
Bench 212
Posting Pro
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
John A 1,896
Vampirical Lurker Team Colleague
jwenting 1,889
duckman Team Colleague
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
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.