1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to make computer shutdown in C

Discussion in 'C' started by jan1024188, Dec 31, 2006.

  1. jan1024188

    jan1024188 New Member

    Joined:
    Dec 31, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    how to make computer shutdown in C?which header do i have to include?
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
  3. tiger12506

    tiger12506 New Member

    Joined:
    Jun 6, 2007
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    For Windows you can

    Code:
    #include <windows.h>
    
    void adjusttoken() {
          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;
    
          AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                  (PTOKEN_PRIVILEGES)NULL, 0);
    
          if (GetLastError() != ERROR_SUCCESS) {
             MessageBox(NULL,"Cannot gain appropriate permission","Shutdown error",0);
          }
    }
    
    int main() {
      adjusttoken();    /* You will probably need this */
      ExitWindowsEx(EWX_POWEROFF|EWX_FORCE,0);
    }
     
  4. LaRoza

    LaRoza New Member

    Joined:
    Jul 27, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <stdio.h>
    int main(void)
    {
        system("SHUTDOWN -s");
        return 0;
    }
    
    This will shutdown Windows XP when run.
     
  5. Vineel567

    Vineel567 New Member

    Joined:
    Nov 23, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0

Share This Page