请问在TC下,如何实现关机(WIN2000系统下)?

解决方案 »

  1.   

    呵呵
    很抱歉,TC的编译器好象不认识WIN32吧
      

  2.   

    HANDLE hToken;              // handle to process token 
    TOKEN_PRIVILEGES tkp;       // pointer to token structure 
     
    if( !OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, 
    &hToken) )
    {
    // For window 98
    ExitWindowsEx(EWX_POWEROFF,0);
    return;
    }// Get the LUID for shutdown privilege. 
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); 
     
    tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
    // Get shutdown privilege for this process.  
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); 
     
    //
    // The return value of AdjustTokenPrivileges can't be tested     
    //
    if (GetLastError() != ERROR_SUCCESS) 
    {
    MessageBox("No Privilege");
    return;
    }ExitWindowsEx(EWX_SHUTDOWN,0);