CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  硬件/系统

请问有关regcreatekeyEx()函数的使用?

楼主nokita(毛豆)2003-06-03 18:51:45 在 VC/MFC / 硬件/系统 提问

如何使用regcreatekeyEx(),特别是里面的参数值怎么设定?最好有例子!谢谢! 问题点数:0、回复次数:2Top

1 楼Xcoder(流浪狗)回复于 2003-06-03 21:26:57 得分 0

看   msdn   啊Top

2 楼nanjianhui(nan)回复于 2003-06-04 12:53:53 得分 0

到msdn里面看一下就知道了,   还有一个例子呢!!!  
  The   following   example   creates   a   security   descriptor   for   a   new   registry   key   using   the   following   process.   Similar   code   can   be   used   to   create   a   security   descriptor   for   other   object   types.    
   
  The   example   fills   an   array   of   EXPLICIT_ACCESS   structures   with   the   information   for   two   ACEs.   One   ACE   allows   read   access   to   everyone;   the   other   ACE   allows   full   access   to   administrators.    
  The   EXPLICIT_ACCESS   array   is   passed   to   the   SetEntriesInAcl   function   to   create   a   DACL   for   the   security   descriptor.    
  After   allocating   memory   for   the   security   descriptor,   the   example   calls   the   InitializeSecurityDescriptor   and   SetSecurityDescriptorDacl   functions   to   initialize   the   security   descriptor   and   attach   the   DACL.    
  The   security   descriptor   is   then   stored   in   a   SECURITY_ATTRIBUTES   structure   and   passed   to   the   RegCreateKeyEx   function,   which   attaches   the   security   descriptor   to   the   newly   created   key.    
  #include   <windows.h>  
  #include   <stdio.h>  
  #include   <aclapi.h>  
   
  void   main(int   argc,   char   *argv[])   {  
   
  DWORD   dwRes,   dwDisposition;  
  PSID   pEveryoneSID   =   NULL,   pAdminSID   =   NULL;  
  PACL   pACL   =   NULL;  
  PSECURITY_DESCRIPTOR   pSD   =   NULL;  
  EXPLICIT_ACCESS   ea[2];  
  SID_IDENTIFIER_AUTHORITY   SIDAuthWorld   =   SECURITY_WORLD_SID_AUTHORITY;  
  SID_IDENTIFIER_AUTHORITY   SIDAuthNT   =   SECURITY_NT_AUTHORITY;  
  SECURITY_ATTRIBUTES   sa;  
  LONG   lRes;  
  HKEY   hkSub   =   NULL;  
   
  //   Create   a   well-known   SID   for   the   Everyone   group.  
   
  if(!   AllocateAndInitializeSid(   &SIDAuthWorld,   1,  
                                    SECURITY_WORLD_RID,  
                                    0,   0,   0,   0,   0,   0,   0,  
                                    &pEveryoneSID)   )   {  
          printf(   "AllocateAndInitializeSid   Error   %u\n",   GetLastError()   );  
          return;  
  }  
   
  //   Initialize   an   EXPLICIT_ACCESS   structure   for   an   ACE.  
  //   The   ACE   will   allow   Everyone   read   access   to   the   key.  
   
  ZeroMemory(&ea,   2   *   sizeof(EXPLICIT_ACCESS));  
  ea[0].grfAccessPermissions   =   KEY_READ;  
  ea[0].grfAccessMode   =   SET_ACCESS;  
  ea[0].grfInheritance=   NO_INHERITANCE;  
  ea[0].Trustee.TrusteeForm   =   TRUSTEE_IS_SID;  
  ea[0].Trustee.TrusteeType   =   TRUSTEE_IS_WELL_KNOWN_GROUP;  
  ea[0].Trustee.ptstrName     =   (LPTSTR)   pEveryoneSID;  
   
  //   Create   a   SID   for   the   BUILTIN\Administrators   group.  
   
  if(!   AllocateAndInitializeSid(   &SIDAuthNT,   2,  
                                    SECURITY_BUILTIN_DOMAIN_RID,  
                                    DOMAIN_ALIAS_RID_ADMINS,  
                                    0,   0,   0,   0,   0,   0,  
                                    &pAdminSID)   )   {  
          printf(   "AllocateAndInitializeSid   Error   %u\n",   GetLastError()   );  
          goto   Cleanup;    
  }  
   
  //   Initialize   an   EXPLICIT_ACCESS   structure   for   an   ACE.  
  //   The   ACE   will   allow   the   Administrators   group   full   access   to   the   key.  
   
  ea[1].grfAccessPermissions   =   KEY_ALL_ACCESS;  
  ea[1].grfAccessMode   =   SET_ACCESS;  
  ea[1].grfInheritance=   NO_INHERITANCE;  
  ea[1].Trustee.TrusteeForm   =   TRUSTEE_IS_SID;  
  ea[1].Trustee.TrusteeType   =   TRUSTEE_IS_GROUP;  
  ea[1].Trustee.ptstrName     =   (LPTSTR)   pAdminSID;  
   
  //   Create   a   new   ACL   that   contains   the   new   ACEs.  
   
  dwRes   =   SetEntriesInAcl(2,   ea,   NULL,   &pACL);  
  if   (ERROR_SUCCESS   !=   dwRes)   {  
          printf(   "SetEntriesInAcl   Error   %u\n",   GetLastError()   );  
          goto   Cleanup;  
  }  
   
  //   Initialize   a   security   descriptor.      
     
  pSD   =   (PSECURITY_DESCRIPTOR)   LocalAlloc(LPTR,    
                                                    SECURITY_DESCRIPTOR_MIN_LENGTH);    
  if   (pSD   ==   NULL)   {    
          printf(   "LocalAlloc   Error   %u\n",   GetLastError()   );  
          goto   Cleanup;    
  }    
     
  if   (!InitializeSecurityDescriptor(pSD,   SECURITY_DESCRIPTOR_REVISION))   {      
          printf(   "InitializeSecurityDescriptor   Error   %u\n",    
                                                          GetLastError()   );  
          goto   Cleanup;    
  }    
     
  //   Add   the   ACL   to   the   security   descriptor.    
     
  if   (!SetSecurityDescriptorDacl(pSD,    
                  TRUE,           //   fDaclPresent   flag        
                  pACL,    
                  FALSE))       //   not   a   default   DACL    
  {      
          printf(   "SetSecurityDescriptorDacl   Error   %u\n",   GetLastError()   );  
          goto   Cleanup;    
  }    
   
  //   Initialize   a   security   attributes   structure.  
   
  sa.nLength   =   sizeof   (SECURITY_ATTRIBUTES);  
  sa.lpSecurityDescriptor   =   pSD;  
  sa.bInheritHandle   =   FALSE;  
   
  //   Use   the   security   attributes   to   set   the   security   descriptor    
  //   when   you   create   a   key.  
     
  lRes   =   RegCreateKeyEx(HKEY_CURRENT_USER,   "mykey",   0,   "",   0,    
                  KEY_READ   |   KEY_WRITE,   &sa,   &hkSub,   &dwDisposition);    
  printf(   "RegCreateKeyEx   result   %u\n",   lRes   );  
   
  Cleanup:  
   
          if   (pEveryoneSID)    
                  FreeSid(pEveryoneSID);  
          if   (pAdminSID)    
                  FreeSid(pAdminSID);  
          if   (pACL)    
                  LocalFree(pACL);  
          if   (pSD)    
                  LocalFree(pSD);  
          if   (hkSub)    
                  RegCloseKey(hkSub);  
          return;  
   
  }  
  Top

相关问题

  • 如何使用RegCreateKeyEx函数?
  • 谁知道BCB中有关“星期”函数的使用方法?
  • delphi5中使用的有关堆栈的函数有什么?
  • 有关键盘钩子函数的使用!(源码分析)
  • 有关于ShellExecute函数的使用,请大家看看
  • 有关于函数....
  • 有关mail( )函数
  • 有关SAVEAS()函数
  • 函数的使用?
  • 一个VC中使用WNet函数的问题(有关编译器的)

关键词

  • ea
  • security
  • access
  • sa
  • trustee
  • padminsid
  • peveryonesid
  • regcreatekeyex
  • descriptor
  • allocateandinitializesid

得分解答快速导航

  • 帖主:nokita

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

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