CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  Windows SDK/API

请教各位 在关闭WIN2000/WIN NT 时是使用的那个参数是什么参数。

楼主caoqizi(我在努力)2003-02-03 11:29:29 在 C++ Builder / Windows SDK/API 提问

请教各位   在关闭WIN200/WIN   NT   时是使用的那个参数是什么参数,我试了几个都不型啊。 问题点数:20、回复次数:9Top

1 楼ilikeff8(迷茫)回复于 2003-02-03 16:17:49 得分 0

?  
  WM_CLOSETop

2 楼huzhangyou(信仰(http://www.libing.net.cn))回复于 2003-02-05 13:08:10 得分 0

他需要adjusttoken  
  参数你可以看看msdn旧可以了  
  网上有很多这样的资料Top

3 楼yeahchang(Studying PKI)回复于 2003-02-05 15:07:54 得分 5

先要:  
  HANDLE   hToken;  
  TOKEN_PRIVILEGES   tkp;  
  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);Top

4 楼szbug(深圳虫)回复于 2003-02-05 16:20:25 得分 0

SHUTDOWNTop

5 楼usingpete(迷失自我)回复于 2003-02-05 16:35:51 得分 0

先要获得管理权限  
  Privileges  
  A   privilege   is   the   right   of   an   account,   such   as   a   user   or   group   account,   to   perform   various   system-related   operations   on   the   local   computer,   such   as   shutting   down   the   system,   loading   device   drivers,   or   changing   the   system   time.   Privileges   differ   from   access   rights   in   two   ways:    
   
  Privileges   control   access   to   system   resources   and   system-related   tasks,   whereas   access   rights   control   access   to   securable   objects.    
  A   system   administrator   assigns   privileges   to   user   and   group   accounts,   whereas   the   system   grants   or   denies   access   to   a   securable   object   based   on   the   access   rights   granted   in   the   ACEs   in   the   object's   DACL.    
  Each   Windows   NT/Windows   2000/Windows   XP   system   has   an   account   database   that   stores   the   privileges   held   by   user   and   group   accounts.   When   a   user   logs   on,   the   system   produces   an   access   token   that   contains   a   list   of   the   user's   privileges,   including   those   granted   to   the   user   or   to   groups   to   which   the   user   belongs.   Note   that   the   privileges   apply   only   to   the   local   computer;   a   domain   account   can   have   different   privileges   on   different   computers.  
   
  When   the   user   tries   to   perform   a   privileged   operation,   the   system   checks   the   user's   access   token   to   determine   whether   the   user   holds   the   necessary   privileges,   and   if   so,   it   checks   whether   the   privileges   are   enabled.   If   the   user   fails   these   tests,   the   system   does   not   perform   the   operation.   For   a   table   of   the   privileges   defined   by   Windows,   see   Windows   NT   Privileges.  
   
  To   determine   the   privileges   held   in   an   access   token,   call   the   GetTokenInformation   function,   which   also   indicates   which   privileges   are   enabled.   Most   privileges   are   disabled   by   default.    
   
  Before   you   can   perform   a   privileged   operation,   you   must   first   enable   the   necessary   privileges   in   your   access   token.   To   do   this,   call   the   OpenThreadToken   function   to   get   a   handle   to   your   primary   or   impersonation   access   token,   then   call   the   AdjustTokenPrivileges   function   to   enable   the   necessary   privileges.   After   performing   the   privileged   operation,   call   AdjustTokenPrivileges   again   to   disable   the   privileges.   For   sample   code   that   enables   and   disables   a   token's   privileges,   see   Enabling   and   Disabling   Privileges.    
   
  The   GetTokenInformation   and   AdjustTokenPrivileges   functions   use   a   TOKEN_PRIVILEGES   structure   to   specify   an   array   of   privileges   and   their   attributes.   This   structure   contains   an   array   of   LUID_AND_ATTRIBUTES   structures,   each   of   which   specifies   the   LUID   of   a   privilege   and   a   set   of   bit   flags   that   indicate   the   attributes   of   the   privilege,   such   as   whether   the   privilege   is   enabled.    
   
  The   Windows   API   defines   a   set   of   string   constants   to   identify   the   various   privileges.   These   constants   are   the   same   on   all   Windows   NT/Windows   2000/Windows   XP   systems.   However,   the   functions   that   get   and   adjust   the   privileges   in   an   access   token   use   the   LUID   type   to   identify   privileges.   The   LUID   values   for   a   privilege   can   differ   from   one   computer   to   another,   and   from   one   boot   to   another   on   the   same   computer.   To   get   the   current   LUID   that   corresponds   to   one   of   the   string   constants,   use   the   LookupPrivilegeValue   function.   Use   the   LookupPrivilegeName   function   to   convert   a   LUID   to   its   corresponding   string   constant.  
   
  The   system   provides   a   set   of   strings   that   describe   each   of   the   Windows   NT   privileges   defined   in   Winnt.h.   These   are   useful   when   you   need   to   display   a   description   of   a   privilege   to   the   user.   Use   the   LookupPrivilegeDisplayName   function   to   retrieve   a   description   string   that   corresponds   to   the   string   constant   for   a   privilege.   For   example,   on   systems   that   use   U.S.   English,   the   display   name   for   the   SE_SYSTEMTIME_NAME   privilege   is   "Change   the   system   time".    
   
  You   can   use   the   PrivilegeCheck   function   to   determine   whether   an   access   token   holds   a   specified   set   of   privileges.   This   is   useful   primarily   to   server   applications   that   are   impersonating   a   client.    
   
  A   system   administrator   can   use   administrative   tools,   such   as   User   Manager,   to   add   or   remove   privileges   for   user   and   group   accounts.   Administrators   can   programmatically   use   the   Lsa   functions   to   work   with   privileges.   The   LsaAddAccountRights   and   LsaRemoveAccountRights   functions   add   or   remove   privileges   from   an   account.   The   LsaEnumerateAccountRights   function   enumerates   the   privileges   held   by   a   specified   account.   The   LsaEnumerateAccountsWithUserRight   function   enumerates   the   accounts   that   hold   a   specified   privilege.  
  摘自msdn  
  再用ExitWindowsExTop

6 楼Behard(我爱天安门)回复于 2003-02-08 10:15:46 得分 10

DWORD   dwVersion   =   GetVersion();  
                  if   (dwVersion   <   0x80000000)   //NT   and   2000  
                  {  
                          HANDLE   hToken;  
                          TOKEN_PRIVILEGES   tkp;  
                          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);  
                          //ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE|EWX_POWEROFF,0);  
                          ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF,0);  
                  }  
                  else                                                 //9X  
                          ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF,0);  
  Top

7 楼tccsdn(紫乐)回复于 2003-02-08 21:32:50 得分 0

同意楼上的Top

8 楼2wuliao(无疗)回复于 2003-02-09 10:34:33 得分 5

HANDLE   hToken;TOKEN_PRIVILEGES   tkp;HANDLE   getHandle;  
   
              getHandle=GetCurrentProcess();  
              OpenProcessToken(getHandle   ,TOKEN_ADJUST_PRIVILEGES,&hToken);  
              LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);  
              tkp.PrivilegeCount   =1;  
              tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;  
              AdjustTokenPrivileges(hToken,false,&tkp,NULL,NULL,NULL);  
              ExitWindowsEx(EWX_POWEROFF,0);Top

9 楼zihan(子寒)回复于 2003-02-10 16:04:27 得分 0

搜索吧,肯定一大堆Top

相关问题

  • 怎样在Win NT下带参数调用命令行程序?
  • 如何请弹出窗口关闭后的返回参数?
  • 如何带参数打开和关闭一个form
  • 如何做并启动带参数的NT服务程序?--------------------
  • c#中执行带有传出参数的数据库存储过程,在取出output参数时,是否要先关闭reader?
  • 参数
  • 参数
  • 关于 php 4.2.1 版关闭 register_globals 后的 url 参数问题,100 求教,在线等待!
  • 还是有关关闭 register_globals 后的 url 参数问题,100 求教,在线等待!
  • 请教如何实现在一个webform关闭时向另一个webform传递参数的功能??

关键词

  • access
  • 参数
  • privileges
  • tkp
  • htoken
  • win
  • token
  • rights

得分解答快速导航

  • 帖主:caoqizi
  • yeahchang
  • Behard
  • 2wuliao

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo