woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

我作这过这个,可在2000下关机

我作这过这个,可在2000下关机  
  void   CCMPCtrlDlg::ShutDownComputer()  
  {  
  HANDLE   hToken;                             //   handle   to   process   token    
  TOKEN_PRIVILEGES   tkp;               //   pointer   to   token   structure    
  if(   !OpenProcessToken(GetCurrentProcess(),  
  TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,  
  &hToken)   )  
  {  
  //   说明运行于98模式下  
  if(   ExitWindowsEx(EWX_SHUTDOWN,0)   !=   0   )  
  EndDialog(IDOK);  
  return;  
  }  
                    //下面的代码是用于2000下的  
                    //修改权限  
  //   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("Adjuste   error!   ");  
  return;  
  }  
  if(   ExitWindowsEx(EWX_SHUTDOWN,0)   ==   0   )  
  return;  
  else  
  EndDialog(IDOK);  
  }

posted on 2008-10-12 15:54 肥仔 阅读(122) 评论(0)  编辑 收藏 引用 所属分类: Windows开发


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理