本人想写一个自动程序,请各位高手指教,需要用到哪些函数,另外请提供一个较详细的思路!谢谢

解决方案 »

  1.   

    主要就是几个消息
    可以考虑用
    InitiateSystemShutdownEx
    ExitWindowsEx
      

  2.   

    BOOL MySystemShutdown()
    {
       HANDLE hToken; 
       TOKEN_PRIVILEGES tkp; 
     
       // Get a token for this process. 
     
       if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
          return( FALSE ); 
     
       // Get the LUID for the 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 the shutdown privilege for this process. 
     
       AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
     
       if (GetLastError() != ERROR_SUCCESS) 
          return FALSE; 
     
       // Shut down the system and force all applications to close. 
     
       if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) 
          return FALSE;    return TRUE;
    }
      

  3.   

    你的操作系统是什么的?如果是XP的,上面的代码足矣!!当然对其他的9X,2000,都行的!!~
      

  4.   

    我刚刚写过一个。呵呵。。
    BOOL CMonitorDlg::RestartComputer()
    {
    HANDLE hToken = NULL;
    TOKEN_PRIVILEGES tkp;
    BOOL fResult = FALSE;
    if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    {
    if(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))
    {
    return ::ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
    }
    }
    }
    return ::ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
    }如果是关机,注销,可以改ExitWindowsEx的参数呵呵