Docstoc

التعامل مع مسجل النظام Registry في VB

Document Sample
التعامل مع مسجل النظام Registry في VB Powered By Docstoc
					‫ﺗﻢ ﺗﺤﻤﻴﻞ اﻟﻤﻠﻒ ﻣﻦ ﻣﻮﻗﻊ‬
    ‫اﻟﺒﻮﺻﻠﺔ اﻟﺘﻘﻨﻴﺔ‬
   ‫‪www.boosla.com‬‬
      ---API---
Registry Functions
      F or Visual Basic



    Syntax Error 0x0 :‫ﺇﻋﺪﺍﺩ‬
       ‫ﻣﻊ ﺩﻋﻢ ﺍﳍﺎﻛﺮ ﺍﳌﻌﻜﻮﻙ‬


            :‫ﻟﻠﻤﺮﺍﺳﻠﺔ‬
     SyntaxErr0x0@yahoo.com
                                  ‫ﺍﳌﻘﺪﻣﺔ‬

  ‫ﺑﺴﻢ ﺍﷲ ﻭﺍﻟﺼﻼﺓ ﻭﺍﻟﺴﻼﻡ ﻋﻠﻰ ﺭﺳﻮﻝ ﺍﷲ ﻭﻋﻠﻰ ﺁﻟﻪ ﻭﺻﺤﺒﻪ ﻭﻣﻦ ﺗﺒﻊ ﻫﺪﺍﻩ ﺇﱃ ﻳﻮﻡ‬
                                                                             ‫ﺍﻟﺪﻳﻦ.‬
                                                                            ‫ﺃﻣﺎ ﺑﻌﺪ:‬
‫ﰲ ﻗﺴﻢ ﺩﻭﺍﻝ ﺍﻟـ‬   ‫‪www.vb4arab.com‬‬    ‫ﻓﻘﺪ ﻗﺮﺃﺕ ﰲ ﻣﻨﺘﺪﻯ ﻓﻴﺠﻮﺍﻝ ﺑﻴﺴﻚ ﻟﻠﻌﺮﺏ‬
‫ﻓﻔﻜﺮﺕ ﺃﻥ ﺃﺟﻌﻞ ﺑﻌﻀﺎﹰ ﻣﻦ ﻭﻗﱵ ﻟﻺﺟﺎﺑﺔ ﻋﻦ‬      ‫‪Registry‬‬   ‫‪ API‬ﺳﺆﺍﻝ ﻋﻦ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺻﺔ ﺑﺎﻟـ‬
                                                                       ‫ﻫﺬﺍ ﺍﻟﺴﺆﺍﻝ.‬


‫ﻣﻼﺣﻈﺔ: ﻟﻦ ﺃﺷﺮﺡ ﻣﺎﻫﻲ ﺍﻟـ ‪ Registry‬ﻭﻛﻴﻔﻴﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻳﺪﻭﻳﺎﹰ ﺷﺮﺣﺎﹰ ﻣﻔﺼﻼﹰ ﻷﻧﻪ ﻳﻔﺘﺮﺽ‬
                                               ‫ﻣﻦ ﺍﻟﻘﺎﺭﻱ ﺃﻥ ﻳﻌﺮﻑ ﻫﺬﻩ ﺍﻷﺷﻴﺎﺀ ﻣﺴﺒﻘﺎﹰ.‬


                                                                     ‫ﻣﻼﺣﻈﺔ ﺃﺧﺮﻯ:‬
‫ﻟﻦ ﻳﺘﻢ ﺷﺮﺡ ﻛﻞ ﺍﻟﺪﻭﺍﻝ ﻣﻊ ﺃﱐ ﺃﻋﺪﻛﻢ ﺑﺸﺮﺣﻬﺎ ﰲ ﺃﻗﺮﺏ ﻭﻗﺖ ﻭﺫﻟﻚ ﻷﺳﺒﺎﺏ ﺧﺎﺻﺔ‬
          ‫ﺳﺄﺷﺮﺣﻬﺎ ﰲ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ ﻭﻷﻱ ﺇﺳﺘﻔﺴﺎﺭﺍﺕ ﻳﺮﺟﻰ ﻣﺮﺍﺳﻠﱵ ﻋﻠﻰ ﺍﻟﻌﻨﻮﺍﻥ ﺍﻟﺘﺎﱄ:‬
                      ‫‪SyntaxErr0x0@yahoo.com‬‬




                                      ‫1‬
                                ‫ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ‬

   ‫ﺃﲰﺎﺀ ﺍﻟﺪﻭﺍﻝ ﻭﺍﻟﺴﺠﻼﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ﺍﳌﺴﺘﺨﺪﻣﺔ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟـ‬
                        Registry

  RegistryDef.bas ‫ ﺑﺎﺳﻢ‬Modules ‫ﻟﻘﺪ ﻗﻤﺖ ﺑﺘﻀﻤﲔ ﻛﻞ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﻟﺴﺠﻼﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ﰲ‬
                                .‫ ﰒ ﻗﻢ ﺑﺎﺳﺘﺪﻋﺎﺀ ﺍﻟﺪﻭﺍﻝ ﻣﺒﺎﺷﺮﺓ‬Project ‫ﻓﻘﻂ ﻗﻢ ﺑﻮﺿﻌﻪ ﰲ ﺍﻟـ‬


                                                                    : ‫ﺍﻟﺪﻭﺍﻝ ﺍﳌﺴﺘﺨﺪﻣﺔ‬
 RegCloseKey                                       RegConnectRegistry
 RegCreateKey                                      RegCreateKeyEx
 RegDeleteKey                                      RegDeleteValue
 RegEnumValue                                      RegEnumKey
 RegEnumKeyEx                                      RegFlushKey
 RegGetKeySecurity                                 RegLoadKey
 RegNotifyChangKeyValue                            RegOpenKey
 RegQueryInfoKey                                   RegQueryMultipleValues
 RegQueryValues                                    RegQueryValueEx
 RegReplaceKey                                     RegRestoreKey
 RegSaveKey                                        RegSetKeySecurity
 RegSetValue                                       RegSetValueEx
 RegUnloadKey




                                                                 :‫ﺍﻟﺴﺠﻼﺕ ﺍﳌﺴﺘﺨﺪﻣﺔ‬
 SECURITY_ATTRIBUTES                               FILETIME
 SECURITY_DESCRIPTOR                               ACL



                                                                    :‫ﺍﻟﺜﻮﺍﺑﺖ ﺍﳌﺴﺘﺨﺪﻣﺔ‬
HKEY_CLASSES_ROOT                           HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER                           HKEY_DYN_DATA
HKEY_LOCAL_MACHINE                          HKEY_PERFORMANCE_DATA
HKEY_USERS                                  ERROR_SUCCESS
ERROR_INSUFFICIENT_BUFFER                   MAX_PATH
READ_CONTROL                                KEY_SET_VALUE
KEY_QUERY_VALUE                             KEY_CREATE_SUB_KEY
KEY_CREATE_LINK                             KEY_ENUMERATE_SUB_KEYS
KEY_EVENT                                   KEY_NOTIFY
SYNCHRONIZE                                 STANDARD_RIGHTS_ALL
STANDARD_RIGHTS_WRITE                       STANDARD_RIGHTS_READ
KEY_READ                                    KEY_WRITE


                                        2
KEY_ALL_ACCESS                     REG_BINARY
REG_CREATED_NEW_KEY                REG_DWORD
REG_DWORD_BIG_ENDIAN               REG_DWORD_LITTLE_ENDIAN
REG_EXPAND_SZ                      REG_NOTIFY_CHANGE_NAME
REG_LINK                           REG_MULTI_SZ
REG_NONE                           REG_NOTIFY_CHANGE_LAST_SET
REG_NOTIFY_CHANGE_SECURITY         REG_OPENED_EXISTING_KEY
REG_OPTION_BACKUP_RESTORE          REG_OPTION_CREATE_LINK
REG_OPTION_NON_VOLATILE            REG_OPTION_RESERVED
REG_OPTION_VOLATILE                REG_REFRESH_HIVE
REG_RESOURCE_LIST                  REG_SZ
REG_WHOLE_HIVE_VOLATILE            REG_LEGAL_CHANGE_FILTER
REG_LEGAL_OPTION                   REG_FULL_RESOURCE_DESCRIPTOR
REG_NOTIFY_CHANGE_ATTRIBUTES       REG_RESOURCE_REQUIREMENTS_LIST




                               3
                                ‫ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ‬

            ‫) ﻓﻜﺮﺓ ﻋﺎﻣﺔ ﻋﻦ ﻛﻴﻔﻴﺔ ﺍﺳﺘﺨﺪﺍﻡ ﻫﺬﻩ ﺍﻟﺪﻭﺍﻝ(‬

                              ‫ﻃﺒﻌﺎﹰ ﻣﻦ ‪ Keys‬ﻭ ‪.Values‬‬   ‫‪Registry‬‬   ‫ﺗﺘﻜﻮﻥ ﺍﻟـ‬
                                                              ‫ﺃﻣﺎ ﺍﻟـ ‪:Keys‬‬
                       ‫‪Keys‬‬   ‫ﻓﻬﻲ ﲢﺘﻮﻱ ﻋﻠﻰ ‪ SubKeys‬ﻭﻫﻲ ﻋﺒﺎﺭﺓ ﻋﻦ‬
                                                 ‫‪Values‬‬   ‫ﻭﲢﺘﻮﻱ ﻋﻠﻰ‬
‫ﻭ ﺑﻔﺘﺢ ﺍﻟـ ‪ Registry‬ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﱪﻧﺎﻣﺞ ‪ regedit.exe‬ﺗﻈﻬﺮ ﻟﻨﺎ ﺍﻟـ ‪ keys‬ﰲ ﺍﻟﻨﺎﺣﻴﺔ‬
                                   ‫ﺍﻟﻴﺴﺮﻯ ﻣﻦ ﺍﻟﺸﺎﺷﺔ ﻭ ﺍﻟـ ‪ Values‬ﰲ ﺍﻟﻨﺎﺣﻴﺔ ﺍﻟﻴﻤﲎ.‬
                                                    ‫ﻭﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﺢ ﺫﻟﻚ:‬




                                       ‫4‬
‫ﳝﻜﻦ ﺇﻧﺸﺎﺀ ﺃﻭ ﺗﻐﻴﲑﺍﻟـ ‪ keys‬ﻭﺍﻟـ ‪ Values‬ﻳﺪﻭﻳﺎﹰ ﺑﺴﻬﻮﻟﺔ ﻭﻟﻜﻦ ﻛﻴﻒ ﳝﻜﻦ ﻓﻌﻞ ﻛﻞ ﺫﻟﻚ ﺑﻠﻐﺔ‬
                                                                      ‫‪ Visual Basic‬؟‬


                  ‫ﻗﺒﻞ ﺍﻟﺒﺪﺀ ﳚﺐ ﻣﻌﺮﻓﺔ ﺑﻌﺾ ﺍﻷﺳﺎﺳﻴﺎﺕ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟـ ‪.Registry‬‬
         ‫1. ﳚﺐ ﻓﺘﺢ ﺍﻟـ ‪ Key‬ﺍﳌﺮﺍﺩ ﻭﺿﻊ ﺃﻭ ﺗﻐﻴﲑ ﺍﻟـ ‪ values‬ﺍﳌﻮﺟﻮﺩﺓ ﺑﺪﺍﺧﻠﻪ‬


                                               ‫2. ﺗﻐﻴﲑ ﺍﻟﻘﻴﻢ ﺍﳌﻮﺟﻮﺩﺓ ﺩﺍﺧﻠﻪ.‬
    ‫3. ﺇﻏﻼﻕ ﺍﻟـ ‪ Key‬ﺍﻟﺬﻱ ﰎ ﻓﺘﺤﻪ. ﻭﻫﺬﻩ ﺍﻟﻨﻘﻄﺔ ﻣﻬﻤﺔ ﺟﺪﺍﹰ ﻷﻧﻪ ﻣﻦ ﺩﻭ‪‬ﺎ ﻻ ﻳﺘﻢ‬
                                          ‫ﻛﺘﺎﺑﺔ ﺍﻟﺒﻴﺎﻧﺎﺕ ﰲ ﺍﻟـ ‪.Registry‬‬


 ‫ﻣﻼﺣﻈﺔ: ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﺒﻴﺎﻧﺎﺕ ﰲ ﺍﻟـ ‪ Registry‬ﺑﺪﻭﻥ ﺇﻏﻼﻕ ﺍﻟـ ‪ Key‬ﻭﺫﻟﻚ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ‬
 ‫ﻭﻟﻜﻦ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺗﺴﺘﺨﺪﻡ ﻣﺼﺎﺩﺭ ﺍﻟﻨﻈﺎﻡ ﺑﺸﻜﻞ ﻛﺒﲑ ﺣﻴﺚ ﻳﺮﺍﻋﻰ ﺍﺳﺘﺨﺪﺍﻣﻬﺎ‬         ‫‪RegFlushKey‬‬

                                                        ‫ﺇﻻ ﰲ ﺣﺎﻻﺕ ﺍﻟﻀﺮﻭﺭﺓ ﺍﻟﻘﺼﻮﻯ.‬


                                                                ‫ﺷﺮﺡ ﺍﻟﻨﻘﺎﻁ ﺍﻟﺴﺎﺑﻘﺔ:‬
                                                             ‫ﻓﺘﺢ ﺍﻟـ ‪.key‬‬      ‫1.‬
‫ﳚﺐ ﻗﺒﻞ ﻓﺘﺢ ‪ key‬ﻣﻌﺮﻓﺔ ‪ handle‬ﻟـ ‪ key‬ﺁﺧﺮ ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻣﻔﺘﻮﺡ ﻣﺴﺒﻘﺎﹰ ﻭﳚﺐ‬
 ‫ﺃﻥ ﻳﻜﻮﻥ ﺍﻟـ ‪ key‬ﺍﳌﺮﺍﺩ ﻓﺘﺤﻪ ﻋﺒﺎﺭﺓ ﻋﻦ ‪ subkey‬ﻟﻠـ ‪ key‬ﺍﻟﺬﻱ ﻳﻮﺟﺪ ﻟﺪﻳﻨﺎ ﺍﻟـ‬
                                                         ‫‪ handle‬ﺍﳋﺎﺹ ﺑﻪ.‬
         ‫ﺗﺘﺴﺂﺀﻝ ﺍﻵﻥ ﻛﻴﻒ ﳝﻜﻨﲏ ﻣﻌﺮﻑ ﺍﻟـ ‪ handle‬ﺍﳋﺎﺹ ﺑﺎﻟـ ‪ key‬ﺍﻷﺏ؟‬
                              ‫ﺇﺟﺎﺑﺔ ﻫﺬﺍ ﺍﻟﺴﺆﺍﻝ ﻋﻨﺪﻱ ﻭﷲ ﺍﳊﻤﺪ ﻭﻫﻲ ﺑﺴﻴﻄﺔ.‬
   ‫ﻳﻌﻄﻲ ﻧﻈﺎﻡ ﺍﻟﺘﺸﻐﻴﻞ ‪ Windows‬ﺃﺭﻗﺎﻡ ﺛﺎﺑﺘﺔ ﻟﻠﻤﻔﺎﺗﻴﺢ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻛﻠﻤﺎ ﰎ ﺗﺸﻐﻴﻞ‬
                          ‫ﺍﻟﻨﻈﺎﻡ ﻭﻫﺬﻩ ﺍﻟـ ‪ keys‬ﻣﻊ ﺍﻟـ ‪ handles‬ﺍﳋﺎﺻﺔ ‪‬ﺎ:‬
                         ‫00000008‪Const HKEY_CLASSES_ROOT = &H‬‬
                        ‫10000008‪Const HKEY_CURRENT_USER = &H‬‬
                      ‫20000008‪Const HKEY_LOCAL_MACHINE = &H‬‬
                                  ‫30000008‪Const HKEY_USERS = &H‬‬
                     ‫50000008‪Const HKEY_CURRENT_CONFIG = &H‬‬
                              ‫60000008‪Const HKEY_DYN_DATA = &H‬‬
                  ‫40000008‪Const HKEY_PERFORMANCE_DATA = &H‬‬
                                                 ‫ﻭﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﺢ ﺍﻟﺴﺎﺑﻖ:‬


                                         ‫5‬
                          ‫‪predefined keys‬‬   ‫ﻭﺗﺴﻤﻰ ﺍﻟـ ‪ keys‬ﺍﻟﺴﺎﺑﻘﺔ ﺑـ‬
                                  ‫ﻭﺍﻟﺪﻭﺍﻝ ﺍﳌﺴﺘﺨﺪﻣﺔ ﻟﻔﺘﺢ ﺍﻟـ ‪ keys‬ﻫﻲ :‬
                                     ‫‪RegOpenKey, RegOpenKeyEx‬‬
                                    ‫‪RegCreateKey,RegCreateKeyEx‬‬
                                                  ‫ﻛﺘﺎﺑﺔ ﻭﺣﺬﻑ ﺍﻟﺒﻴﺎﻧﺎﺕ:‬     ‫2.‬
                                             ‫ﳝﻜﻦ ﺍﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﻭﺍﻝ ﺍﻟﺘﺎﻟﻴﺔ:‬
  ‫‪key‬‬   ‫‪ RegSetValueEx, RegSetValue‬ﻭﺫﻟﻚ ﻟﺘﺨﺼﻴﺺ ﺑﻴﺎﻧﺎﺕ )‪ (Data‬ﻟـ‬
                                                                  ‫ﻣﻌﲔ.‬
           ‫‪ :RegSetValue‬ﺗﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﻓﻘﻂ، ﻭﺳﺄﰐ ﺷﺮﺣﻬﺎ ﰲ ﺣﻴﻨﻬﺎ.‬
‫‪ :RegSetValueEx‬ﳝﻜﻨﻬﺎ ﻛﺘﺎﺑﺔ ﺃﻱ ﻧﻮﻉ ﻣﻦ ﺍﻟﺒﻴﺎﻧﺎﺕ ﻭﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﻣﻜﺎ‪‬ﺎ ﺇﻧﺸﺎﺀ‬
                                 ‫‪ key‬ﻭ ‪ value‬ﺧﺎﺹ ﺑﻪ ﰲ ﻧﻔﺲ ﺍﻟﻮﻗﺖ!!!‬
                 ‫‪RegDeleteValue‬‬    ‫ﻭﳊﺬﻑ ‪ Value‬ﻣﻦ ‪ key‬ﺗﺴﺘﺨﺪﻡ ﺍﻟﺪﺍﻟﺔ‬
‫ﻣﻊ ﻣﻼﺣﻈﺔ ﺃﻥ ﺍﻟـ ‪ key‬ﺍﶈﺬﻭﻑ‬     ‫‪RegDeleteKey‬‬    ‫ﻭﳊﺬﻑ ‪ key‬ﻧﺴﺘﺨﺪﻡ ﺍﻟﺪﺍﻟﺔ‬
                                 ‫ﻻﻳﺘﻢ ﺇﺯﺍﻟﺘﻪ ﺣﱴ ﻳﺘﻢ ﻗﻔﻞ ﺁﺧﺮ ‪ handle‬ﻟﻪ.‬
                    ‫‪RegSetKeySecurity‬‬      ‫ﻭﻟﺘﻐﻴﲑ ﺃﻣﺎﻥ ﺍﻟـ ‪ keys‬ﻧﺴﺘﺨﺪﻡ‬


                                       ‫6‬
‫ﳝﻜﻦ ﺟﻠﺐ ﺍﻟـ ‪ subkeys‬ﻟـ ‪ key‬ﻣﻌﲔ ﺣﱴ ﻳﺘﻢ ﺇﳚﺎﺩ ‪ key‬ﻣﻌﲔ ﻭﺃﺧﺬ ﺍﻟﺒﻴﺎﻧﺎﺕ ﻣﻨﻪ‬
‫ﺃﻣﺎ ﺍﻷﻭﱃ‬   ‫‪RegEnumKeyEx‬‬        ‫ﻭﺫﻟﻚ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ: ‪ RegEnumKey‬ﺃﻭ ﺍﻟﺪﺍﻟﺔ‬
           ‫‪Classes‬‬   ‫ﺗﺮﺟﻊ ﺍﻟـ ‪ subkeys‬ﻓﻘﻂ ﻭﺍﻟﺜﺎﻧﻴﺔ ﺗﺮﺟﻊ ﺍﻟـ ‪ subkeys‬ﻣﻊ ﺍﻟـ‬
    ‫ﻣﻌﻴﻨﺔ، ﺍﻟﱪﻧﺎﻣﺞ ﳝﻜﻦ ﺃﻥ ﺗﺴﺘﺪﻋﻲ ﺍﻟﺪﺍﻟﺔ‬    ‫‪subkey‬‬   ‫ﻹﺭﺟﺎﻉ ﺑﻴﺎﻧﺎﺕ ﻣﻔﺼﻠﺔ ﺣﻮﻝ‬
                                                          ‫‪RegQueryInfoKey‬‬
 ‫ﻭﺍﻟﺪﺍﻟﺔ ‪ RegGetKeySecurity‬ﺗﺮﺟﻊ ﻧﺴﺨﺔ ﻣﻦ ﺍﻟـ ‪ SecurityDescription‬ﺍﻟﱵ‬
                                                                 ‫‪key‬‬   ‫ﲢﻤﻲ ﺍﻟـ‬
                 ‫‪RegEnumValue‬‬       ‫ﻭﳉﻠﺐ ﺍﻟـ ‪ values‬ﻟـ ‪ key‬ﺗﺴﺘﺨﺪﻡ ﺍﻟﺪﺍﻟﺔ‬
                            ‫‪RegCloseKey‬‬      ‫ﺇﻏﻼﻕ ﺍﻟـ ‪ key‬ﻳﺘﻢ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ‬       ‫3.‬


                         ‫ﻛﻞ ﻣﺎﻋﻠﻴﻚ ﻓﻬﻤﻪ ﻣﻦ ﺍﻟﻨﻘﺎﻁ ﺍﻟﺴﺎﺑﻘﺔ ) ﺇﻥ ﱂ ﺗﻔﻬﻢ ﺷﻴﺌﺎﹰ ﻣﻨﻪ ( ﻫﻮ ﺍﻟﺘﺎﱄ:‬
             ‫ﳚﺐ ﻓﺘﺢ ﺍﻟـ ‪ key‬ﰒ ﺗﻐﲑ ﻓﻌﻞ ﻣﺎﺗﺮﻳﺪ ﻋﻠﻴﻪ ﰒ ﺑﻌﺪ ﺫﻟﻚ ﺇﻏﻼﻗﻪ .‬


                          ‫ﻳﻮﺟﺪ ﺑﺮﻧﺎﻣﺞ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ 10 ‪ Examp‬ﻓﻴﻪ ﺑﻌﺾ ﺍﻟﺪﻭﺍﻝ ﺍﻟﺴﺎﺑﻘﺔ.‬


               ‫ﻟﻘﺪ ﻗﻤﺖ ﺑﺸﺮﺡ ﻋﺎﻡ ﻋﻠﻰ ﺑﻌﺾ ﺍﻟﺪﻭﺍﻝ ﻭﺇﻟﻴﻚ ﺑﺸﺮﺡ ﻣﻔﺼﻞ.‬




                                             ‫7‬
                               ‫ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ‬

                      ‫ﺷﺮﺡ ﺑﻌﺾ ﺍﻟﺪﻭﺍﻝ ﺑﺎﻟﺘﻔﺼﻴﻞ‬

  ‫ﱂ ﺃﺷﺮﺡ ﻛﻞ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟـ ‪ Registry‬ﻟﺴﺒﺐ ﺿﻴﻖ ﺍﻟﻮﻗﺖ ﺍﻟﺬﻱ‬
‫ﻗﻤﺖ ﺑﻜﺘﺎﺑﺔ ﻫﺬﺍ ﺍﳌﻮﺿﻮﻉ ﻓﻴﻪ ﺇﺫ ﺃﻧﲏ ﻛﺘﺒﺖ ﻭﺭﺗﺒﺖ ﻛﻞ ﻫﺬﺍ ﰲ ﺧﻼﻝ ﻳﻮﻡ ﻭﺍﺣﺪ ﻭﻧﺼﻒ ﻭﺃﲪﺪ‬
                 ‫ﺍﷲ ﺃﻧﻪ ﻳﻮﺟﺪ ﻟﺪﻱ ﻛﻮﺩ ﻛﺘﺒﺘﻪ ﻣﺴﺒﻘﺎ ﰲ ﻭﻗﺖ ﻓﺮﺍﻏﻲ ﻭﺃﺭﻓﻘﺘﻪ ﻣﻊ ﻫﺬﺍ ﺍﳌﻠﻒ.‬
 ‫ﻣﻊ ﺃﻧﲏ ﺃﻋﺪﻛﻢ ﺑﺄﻧﲏ ﺳﺄﺷﺮﺡ ﻫﺬﻩ ﺍﻟﺪﻭﺍﻝ ﻭﺍﻟﺪﻭﺍﻝ ﺍﻷﺧﺮﻯ ﻋﻨﺪﻣﺎ ﺃﺟﺪ ﻭﻗﺖ ﻓﺮﺍﻍ ﺇﺫ‬
                                                       ‫ﺃﻧﲏ ﻣﺸﻐﻮﻝ ﲟﺸﺮﻭﻉ ﺍﻟﺘﺨﺮﺝ.‬
‫ﻣﻊ ﺍﻟﻌﻠﻢ ﺑﺄﻧﲏ ﺍﺧﺘﺮﺕ ﺃﻫﻢ ﺍﻟﺪﻭﺍﻝ، ﻭﻻ ﺃﻋﺘﻘﺪ ﺃﻥ ﺍﻟﺪﻭﺍﻝ ﺍﻷﺧﺮﻯ ﺳﺘﻜﻮﻥ ﺫﺍﺕ ﺃﳘﻴﺔ ﻛﺒﲑﺓ ﻟﻜﻢ‬
                   ‫ﻋﻠﻰ ﺍﻷﻗﻞ ﰲ ﺍﻟﻮﻗﺖ ﺍﳊﺎﱄ ﺣﱴ ﻳﺘﺴﲎ ﱄ ﺍﻟﻮﻗﺖ ﻟﻜﻲ ﺃﻛﻤﻞ ﻟﻜﻢ ﺍﻟﺒﻘﻴﺔ.‬




                                       ‫8‬
                  ‫**ﺍﻟﺒﺎﺏ ﺍﻷﻭﻝ: ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟـ ‪**Keys‬‬

                                                   ‫ﺍﻟﺪﺍﻟﺔ ﺍﻷﻭﱃ: ‪RegCloseKey‬‬
                    ‫ﻫﻲ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺈﺯﺍﻟﺔ ﺍﳊﺠﺰ ﻋﻦ ‪ key‬ﰎ ﻓﺘﺤﻪ ﻭﺗﻌﺮﻳﻔﻬﺎ ‪‬ﺬﺍ ﺍﻟﺸﻜﻞ:‬


                                         ‫ﺗﺴﺘﻘﺒﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣﻌﺎﻣﻞ ﻭﺍﺣﺪ ﻓﻘﻂ ﻭﻫﻮ:‬
                                 ‫‪ : hKey‬ﻫﻮ ﺍﻟـ ‪ handle‬ﻟـ ‪ key‬ﰎ ﻓﺘﺤﻪ‬
  ‫‪ERROR_SUCCESS‬‬            ‫ﺇﺫﺍ ﳒﺤﺖ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻓﺈ‪‬ﺎ ﺳﺘﺮﺟﻊ ﺍﻟﻘﻴﻤﺔ‬
       ‫ﻭﺍﻟﱵ ﺗﺴﺎﻭﻱ 0 , ﺃﻣﺎ ﺇﺫﺍ ﺃﺧﻔﻘﺖ ﻓﺈ‪‬ﺎ ﺗﺮﺟﻊ ﻗﻴﻤﺔ ﻏﲑ ﺍﻟﺼﻔﺮ.‬
‫ﺍﻟﺬﻱ ﰎ ﻗﻔﻠﻪ ﺇﻻ ﺇﺫﺍ ﰎ‬   ‫‪handle‬‬   ‫ﻣﻊ ﻣﻼﺣﻈﺔ ﺃﻧﻪ ﻻﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟـ‬
       ‫ﻓﺘﺢ ﺍﻟـ ‪ key‬ﻣﻦ ﺟﺪﻳﺪ ﻣﻊ ﻣﻼﺣﻈﺔ ﺃﻥ ﺍﻟـ ‪ handle‬ﺳﻴﺘﻐﲑ.‬
‫ﻭﻋﻠﻴﻚ ﺃﻥ ﻻﺗﺘﺮﻙ ﺍﻟـ ‪ key‬ﻣﻔﺘﻮﺡ ﺃﻛﺜﺮ ﻣﻦ ﺍﻟﻮﻗﺖ ﺍﻟﺬﻱ ﺗﺴﺘﻌﻤﻠﻪ ﻓﻴﻪ.‬
‫‪Registry‬‬   ‫ﻣﻊ ﻣﻼﺣﻈﺔ ﺃﻧﻪ ﻻ ﻳﺘﻢ ﲣﺰﻳﻦ ﺍﻟﺒﻴﺎﻧﺎﺕ ﺍﻟﱵ ﰎ ﺇﺿﺎﻓﺘﻬﺎ ﺇﱃ ﺍﻟـ‬
                                 ‫ﻓﻌﻠﻴﺎﹰ ﺇﻻ ﻋﻨﺪﻣﺎ ﻳﺘﻢ ﻗﻔﻞ ﺍﻟـ ‪.Key‬‬
 ‫ﻭﻋﻨﺪ ﻛﺘﺎﺑﺔ ﺑﻴﺎﻧﺎﺕ ﻛﺒﲑﺓ ﺟﺪﺍﹰ ﰲ ﺍﻟـ ‪ Registry‬ﻭﺗﻨﻔﻴﺬ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻗﺪ‬
                ‫ﺗﺄﺧﺬ ﺑﻀﻊ ﺛﻮﺍﱐ ﰲ ﲣﺰﻳﻦ ﺍﻟﺒﻴﺎﻧﺎﺕ ﰲ ﺍﻟـ ‪.Registry‬‬




                                          ‫9‬
                                                 ‫ﺍﻟﺪﺍﻟﺔ ﺍﻟﺜﺎﻧﻴﺔ: ‪RegCreateKey‬‬
             ‫ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ‪ key‬ﳏﺪﺩ ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﻣﻮﺟﻮﺩﺍﹰ ﻓﺈ‪‬ﺎ ﺗﻘﻮﻡ ﺑﻔﺘﺤﻪ.‬
   ‫ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣﺘﻮﺍﻓﻘﺔ ﻣﻊ ﻧﻈﺎﻡ 1.3 ‪ .Windows‬ﺃﻣﺎ ﺍﻟﱪﺍﻣﺞ ﺍﳌﻌﺘﻤﺪﺓ ﻋﻠﻰ 23‪ win‬ﻓﻤﻦ ﺍﻷﻓﻀﻞ‬
               ‫ﻭﺍﻟﱵ ﺳﺄﻗﻮﻡ ﺑﺸﺮﺣﻬﺎ ﺑﻌﺪ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ.‬     ‫‪RegCreateKeyEx‬‬           ‫ﺇﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ‬


                ‫‪hKey, lpSubKey,phkResult‬‬         ‫ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺎﺳﺘﻘﺒﺎﻝ ﺛﻼﺙ ﻣﻌﺎﻣﻼﺕ :‬
                               ‫‪Long‬‬       ‫ﻣﻦ ﻧﻮﻉ‬                             ‫‪: hKey‬‬
   ‫‪Predefinedkeys‬‬   ‫ﻳﺸﲑ ﺇﱃ ‪ handle‬ﻟـ ‪ key‬ﻣﻔﺘﻮﺡ ﺣﺎﻟﻴﺎﹰ، ﺃﻭ ﺃﻱ ﻣﻦ ﺍﻟـ‬
                 ‫)ﺭﺍﺟﻊ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ ﳌﻌﺮﻓﺔ ﻣﺎﻫﻲ ﺍﻟـ ‪( PredefinedKeys‬‬
            ‫ﺍﳌﻌﺮﻑ ﺑﻮﺍﺳﻄﺔ ‪.hKey‬‬    ‫‪key‬‬   ‫ﻭﺍﻟـ ‪ key‬ﺍﳌﻨﺸﺄ ﻫﻮ ‪ subkey‬ﻟـ‬


                                        ‫‪String‬‬     ‫ﻣﻦ ﻧﻮﻉ‬           ‫‪: lpSubKey‬‬
‫ﳛﺪﺩ ﺇﺳﻢ ﺍﻟـ ‪ Key‬ﺍﳌﺮﺍﺩ ﺇﻧﺸﺎﺀﻩ ﺃﻭ ﻓﺘﺤﻪ ﻭﻫﺬﺍ ﺍﻟـ ‪ Key‬ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻣﻔﺘﺎﺡ‬
                                     ‫ﺍﶈﺪﺩ ﰲ ‪.hKey‬‬       ‫ﺍﻟـ‪Key‬‬   ‫ﻓﺮﻋﻲ ﻣﻦ‬
                         ‫ﻭﳝﻜﻦ ﺃﻥ ﻳﻜﻮﻥ ﺇﺳﻢ ﻭﺍﺣﺪ ﺃﻭ ﻣﺴﺎﺭ ‪‬ﺬﺍ ﺍﻟﺸﻜﻞ:‬
                                                       ‫"‪"SOFTWARE‬‬
                                                                        ‫ﺃﻭ‬
       ‫"‪"\SOFTWARE\Microsoft\Windows\CurrentVersion\Run‬‬


                                         ‫‪Long‬‬      ‫ﻣﻦ ﻧﻮﻉ‬            ‫‪:phkResult‬‬
       ‫ﻳﺆﺷﺮ ﺇﱃ ﻣﺘﻐﲑ ﻳﺴﺘﻘﺒﻞ ﺍﻟـ ‪ Handle‬ﺍﳋﺎﺹ ﺑﺎﻟـ ‪ Key‬ﺍﻟﱵ ﰎ ﻓﺘﺤﻬﺎ.‬


                                                                   ‫ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺟﻌﺔ:‬
              ‫ﺇﺫﺍ ﳒﺤﺖ.‬   ‫‪ERROR_SUCCESS‬‬              ‫ﺗﺮﺟﻊ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺍﻟﻘﻴﻤﺔ‬
                                                                                   ‫ﻣﻼﺣﻈﺔ:‬
                                      ‫ﳝﻜﻦ ﺇﻧﺸﺎﺀ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟـ ‪ Keys‬ﺍﳌﺘﺪﺍﺧﻠﺔ.‬


                                      ‫20 ‪Examp‬‬      ‫ﻭﻣﺜﺎﻝ ﻋﻠﻰ ﺫﻟﻚ ﻳﻮﺟﺪ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ‬



                                          ‫01‬
                                              ‫ﺍﻟﺪﺍﻟﺔ ﺍﻟﺜﺎﻟﺜﺔ: ‪RegCreateKeyEx‬‬
‫ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺗﺸﺒﻪ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺴﺎﺑﻘﺔ ﻣﻦ ﺣﻴﺚ ﺃ‪‬ﺎ ﺗﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ‪ Key‬ﺃﻭ ﺗﻔﺘﺤﻪ ﺇﻥ ﻛﺎﻥ ﻣﻮﺟﻮﺩﺍﹰ‬
                                                          ‫ﻭﺗﺴﺘﻘﺒﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺗﺴﻊ ﻣﻌﺎﻣﻼﺕ :‬
‫,‪hKey, lpSubKey, vReserved, lpClass, dwOption, samDesired‬‬
‫‪lpSecurityAttributes, phkResult, lpdwDisposition‬‬

                                                   ‫‪Long‬‬     ‫ﻣﻦ ﺍﻟﻨﻮﻉ‬             ‫‪:hKey‬‬
      ‫) ﺭﺍﺟﻊ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺴﺎﺑﻘﺔ (‬       ‫ﳌﻔﺘﺎﺡ ﻣﻔﺘﻮﺡ ﺣﺎﻟﻴﺎﹰ‬     ‫‪Handle‬‬   ‫ﻗﻴﻤﺔ ﺍﻟـ‬


                                         ‫‪String‬‬     ‫ﻣﻦ ﺍﻟﻨﻮﻉ‬            ‫‪:lpSubKey‬‬
   ‫ﻳﺸﲑ ﺇﱃ ﻣﺘﻐﲑ ﻧﺼﻲ ﳛﻤﻞ ﺍﺳﻢ ﺍﻟـ ‪ subkey‬ﺍﻟﺬﻱ ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻣﺘﻔﺮﻉ ﻣﻦ‬
                                                  ‫ﺍﳌﻔﺘﺎﺡ ﺍﳌﺸﺎﺭ ﺇﻟﻴﻪ ﺑـ ‪.hKey‬‬
  ‫ﻣﻊ ﻣﻼﺣﻈﺔ ﺃﻥ ﺍﻟﻨﺺ ﳚﺐ ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺑـ "\" ﻭﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﻻ ﳝﻜﻦ ﺃﻥ ﻳﻜﻮﻥ‬
                                                                       ‫ﻓﺎﺭﻏﺎﹰ.‬


                                 ‫‪Long‬‬      ‫ﻣﻦ ﺍﻟﻨﻮﻉ‬                     ‫‪: Reserved‬‬
                                   ‫ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﳏﺠﻮﺯ ﻭﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﺻﻔﺮ.‬


                                ‫‪String‬‬     ‫ﻣﻦ ﺍﻟﻨﻮﻉ‬                         ‫‪:lpClass‬‬
                          ‫‪key‬‬   ‫ﻣﺘﻐﲑ ﻧﺼﻲ ﳛﻮﻱ ﻧﻮﻉ ﺍﻟـ ‪ Object‬ﳍﺬﺍ ﺍﻟـ‬
                       ‫ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟـ ‪ key‬ﻣﻮﺟﻮﺩ ﻓﺈﻥ ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﻳﺘﺠﺎﻫﻞ.‬
                      ‫ﻟﻦ ﺃﺷﺮﺡ ﺍﻟـ ‪ Classes‬ﺍﻵﻥ ﳌﺎ ﳛﺘﺎﺟﻪ ﻣﻦ ﻭﻗﺖ ﻭﺟﻬﺪ.‬

                                           ‫‪Long‬‬       ‫ﻣﻦ ﻧﻮﻉ‬            ‫‪:dwOption‬‬
       ‫0002 ‪Windows‬‬     ‫ﻣﻼﺣﻈﺔ: ﻫﺬﻩ ﺍﳋﺎﺻﻴﺔ ﻣﻮﺟﻮﺩﺓ ﰲ ‪ Windows NT‬ﻭ‬
                                    ‫ﺃﻣﺎ ﰲ ‪ Windows 9x‬ﻓﺈﻧﻪ ﻳﺘﻢ ﲡﺎﻫﻠﻬﺎ.‬


                                ‫ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﳛﺪﺩ ﺧﻴﺎﺭﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟـ ‪.Key‬‬
                                 ‫ﻭﻫﺬﺍ ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻭﺍﺣﺪﺍﹰ ﻣﻦ ﺍﻟﻘﻴﻢ ﺍﻟﺘﺎﻟﻴﺔ:‬
‫‪REG_OPTION_NON_VOLATILE‬‬                   ‫‪or REG_OPTION_VOLATILE‬‬


                                            ‫11‬
                                ‫‪REG_OPTION_NON_VOLATILE‬‬
  ‫ﺍﳌﻔﺘﺎﺡ ﺍﳌﻨﺸﺄ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻫﺬﺍ ﺍﻟﺜﺎﺑﺖ ﻟﻴﺲ ﻣﻦ ﺍﻟﺴﻬﻮﻟﺔ ﺿﻴﺎﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ‬
  ‫ﺍﳌﻮﺟﻮﺩﺓ ﺑﻪ ﻭﻫﺬﺍ ﻫﻮ ﺍﳋﻴﺎﺭ ﺍﻻﻓﺘﺮﺍﺿﻲ. ﺣﻴﺚ ﺃﻥ ﺍﳌﻌﻠﻮﻣﺎﺕ ﲣﺰﻥ ﰲ‬
                    ‫ﻣﻠﻒ ﻭﲢﻤﻰ ﺃﻭ ﲢﻔﻆ ﻋﻨﺪﻣﺎ ﻳﻌﺎﺩ ﺗﺸﻐﻴﻞ ﺍﻟﻨﻈﺎﻡ.‬

                                       ‫‪REG_OPTION_VOLATILE‬‬
  ‫ﺍﻟـ ‪ Key‬ﺍﳌﻨﺸﺄ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻫﺬﺍ ﺍﻟﺜﺎﺑﺖ ﲣﺰﻥ ﰲ ﺍﻟﺬﺍﻛﺮﺓ ﻭﻏﲑ ﳏﻔﻮﻇﺔ‬
                                                        ‫ﺣﻔﻆ ﺟﻴﺪ‬
                 ‫ﻭﻫﺬﺍ ﺍﻟﺜﺎﺑﺖ ﻳﺘﻢ ﲡﺎﻫﻠﻪ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟـ ‪ key‬ﻣﻮﺟﻮﺩ.‬

                            ‫‪REG_OPTION_BACKUP_RESTORE‬‬
‫‪samDesired‬‬   ‫ﺇﺫﺍ ﻛﺎﻧﺖ ﻫﺬﺍ ﺍﻟﺜﺎﺑﺖ ﻣﻮﺟﻮﺩ ﻓﺈﻥ ﺍﻟﺪﺍﻟﺔ ﺗﺘﺠﺎﻫﻞ ﺍﳌﻌﺎﻣﻞ‬
    ‫‪Restore, Backup‬‬      ‫ﻭﺗﻌﻄﻲ ﺻﻼﺣﻴﺔ ﻓﺘﺢ ﺍﻟـ ‪ key‬ﻋﻠﻰ ﺃﺳﺎﺱ‬


                               ‫‪Long‬‬      ‫ﻣﻦ ﻧﻮﻉ‬                      ‫‪samDesired‬‬

             ‫ﻳﺒﲔ ﻛﻴﻔﻴﺔ ﺃﻭ ﻧﻮﻉ ﺍﻷﻣﻦ ﺍﳌﺮﺍﺩ ﺍﺳﺘﺨﺪﺍﻣﻪ ﻟﻠـ ‪ key‬ﺍﳌﺮﺍﺩ ﻓﺘﺤﻪ.‬
                         ‫ﻭﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﳝﻜﻦ ﺃﻥ ﻳﻜﻮﻥ ﻣﺰﳚﺎﹰ ﻣﻦ ﺍﻟﻘﻴﻢ ﺍﻟﺘﺎﻟﻴﺔ:‬
‫‪KEY_ALL_ACCESS‬‬                                ‫ﳝﻜﻨﻚ ﺍﻟﻘﻴﺎﻡ ﺑﺄﻱ ﺷﻲﺀ ﳑﻜﻦ‬
‫‪KEY_CREATE_LINK‬‬                               ‫ﺻﻼﺣﻴﺔ ﺇﻧﺸﺎﺀ ﺭﺑﻂ ﺭﻣﺰﻱ‬
‫‪KEY_CREATE_SUB_KEY‬‬                            ‫ﺇﻣﻜﺎﻧﻴﺔ ﺇﻧﺸﺎﺀ ﻣﻔﺎﺗﻴﺢ ﻓﺮﻋﻴﺔ‬
‫‪KEY_ENUMERATE_SUB_KEYS‬‬                        ‫ﺻﻼﺣﻴﺔ ﻋﺪ ﻭﻣﻌﺮﻓﺔ ﺃﲰﺎﺀ ﺍﳌﻔﺎﺗﻴﺢ ﺍﻟﻔﺮﻋﻴﺔ‬
‫‪KEY_EXECUTE‬‬                                   ‫ﺻﻼﺣﻴﺔ ﻗﺮﺍﺀﺓ ﻭﺗﻨﻔﻴﺬ‬
‫‪KEY_NOTIFY‬‬                                    ‫ﺻﻼﺣﻴﺔ ﺍﻹﻋﻼﻡ ﺑﺎﻟﺘﻐﻴﲑ‬
‫‪KEY_READ‬‬                            ‫ﺧﻠﻴﻂ ﻣﻦ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺼﻼﺣﻴﺎﺕ‬
‫‪KEY_SET_VALUE‬‬                       ‫ﺻﻼﺣﻴﺔ ﺗﻐﻴﲑ ﺑﻴﺎﻧﺎﺕ ﺍﳌﻔﺎﺗﻴﺢ ﺍﻟﻔﺮﻋﻴﺔ‬
‫‪KEY_WRITE‬‬                                     ‫ﺧﻠﻴﻂ ﻣﻦ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺼﻼﺣﻴﺎﺕ‬


 ‫: ‪SECURITY_ATTRIBUTES‬‬          ‫ﻣﻦ ﻧﻮﻉ ﺍﻟﺘﺮﻛﻴﺒﺔ‬           ‫‪lpSecurityAttributes‬‬




                                         ‫21‬
    ‫ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﳛﺪﺩ ﻫﻞ ﺍﻟـ ‪ handle‬ﺍﳌﺮﺟﻊ ﳝﻜﻦ ﺃﻥ ﻳﻜﻮﻥ ﻣﻮﺭﻭﺛـﺎﹰ ﺑﻮﺍﺳﻄﺔ‬
             ‫ﺍﳌﻌﺎﳉﺔ ﺍﻹﺑﻦ )ﻭﻟﻦ ﺃﻓﺼﻞ ﻫﺬﻩ ﺍﻟﻨﻘﻄﺔ ﳌﺎ ﻳﺘﻄﻠﺒﻪ ﻣﻦ ﻭﻗﺖ ﻭﺟﻬﺪ(.‬
   ‫ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ‪ NULL‬ﻓﺈﻥ ﺍﻟـ ‪ handle‬ﻻ ﳝﻜﻦ ﺃﻥ ﻳﻮﺭﺙ ﳌﻌﺎﳉﺔ‬
                                                                      ‫ﺇﺑﻦ.‬
                                             ‫ﻭﺳﺄﺷﺮﺡ ﻫﺬﻩ ﺍﻟﺘﺮﻛﻴﺒﺔ ﺑﻌﺪ ﻗﻠﻴﻞ.‬
                                       ‫ﲢﺖ ﻧﻈﺎﻡ ﺍﻟﺘﺸﻐﻴﻞ ‪: Windows NT‬‬
  ‫ﺍﻟﻌﻨﺼﺮ ‪ lpSecurityDescriptor‬ﰲ ﻫﺬﻩ ﺍﻟﺘﺮﻛﻴﺒﺔ ﻳﻮﺿﺢ ﺻﻔﺔ ﺍﻷﻣﺎﻥ‬
     ‫‪Defaults‬‬   ‫ﻟﻠﻤﻔﺘﺎﺡ ﺍﳉﺪﻳﺪ ﻭﺇﻥ ﻛﺎﻥ ‪ NULL‬ﻓﺈﻥ ﺍﻷﻣﻦ ﻳﺄﺧﺪ ﺍﻟـ‬


                                        ‫ﲢﺖ ﻧﻈﺎﻡ ﺍﻟﺘﺸﻐﻴﻞ ‪: Windows 9x‬‬
                                ‫ﺍﻟﻌﻨﺼﺮ ‪ lpSecurityDescriptor‬ﻳﺘﻢ ﲡﺎﻫﻠﻪ.‬


                         ‫‪Long‬‬     ‫ﻣﻦ ﺍﻟﻨﻮﻉ‬                          ‫‪: phkResult‬‬
‫ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻮﺿﻊ ﺍﻟـ ‪ handle‬ﻟﻠـ ‪ key‬ﺍﳌﻔﺘﻮﺡ ﺃﻭ ﺍﳌﻨﺸﺄ ﻟﻴﺘﻢ ﺇﺳﺘﺨﺪﺍﻣﻪ‬
                                                            ‫ﻣﻦ ﻗﺒﻞ ﺍﳌﱪﻣﺞ.‬


                 ‫‪Long‬‬    ‫ﻣﻦ ﺍﻟﻨﻮﻉ:‬                            ‫‪: lpdwDesposition‬‬
                                      ‫ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ ﺑﻮﺿﻊ ﺇﺣﺪﻯ ﺍﻟﻘﻴﻢ ﺍﻟﺘﺎﻟﻴﺔ:‬
       ‫‪REG_CREATED_NEW_KEY‬‬
       ‫‪REG_OPENED_EXISTING_KEY‬‬
‫ﺃﻣﺎ ﺍﻷﻭﻝ ﻓﻴﺪﻝ ﻋﻠﻰ ﺃﻥ ﺍﳌﻔﺘﺎﺡ ﻟﻴﺲ ﻣﻮﺟﻮﺩ ﻭﰎ ﺇﻧﺸﺎﺀﻩ، ﺃﻣﺎ ﺍﻟﺜﺎﱐ ﻓﺈﻧﻪ ﻳﺪﻝ ﻋﻠﻰ‬
                        ‫ﺃﻥ ﺍﳌﻔﺘﺎﺡ ﻣﻮﺟﻮﺩ ﻭﻟﻜﻦ ﰎ ﻓﺘﺤﻪ ﻓﻘﻂ ﺑﺪﻭﻥ ﺃﻱ ﺗﻐﻴﲑ.‬
‫ﳝﻜﻦ ﺍﻻﺳﺘﻔﺎﺩﺓ ﻣﻦ ﻫﺬﻩ ﺍﻟﻘﻴﻤﺔ ﳌﻌﺮﻓﺔ ﻫﻞ ﻫﺬﻩ ﻫﻲ ﺃﻭﻝ ﻣﺮﺓ ﰎ ﻓﻴﻬﺎ ﻓﺘﺢ ﺍﻟﱪﻧﺎﻣﺞ‬
                                                                     ‫ﺃﻡ ﻻ؟‬


                                                           ‫ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺟﻌﺔ ﻣﻦ ﺍﻟﺪﺍﻟﺔ:‬
                 ‫‪ERROR_SUCCESS‬‬           ‫ﺇﺫﺍ ﳒﺤﺖ ﺍﻟﺪﺍﻟﺔ ﻓﺈ‪‬ﺎ ﺗﺮﺟﻊ ﺍﻟﻘﻴﻤﺔ‬
‫ﻳﻮﺟﺪ ﻣﺜﺎﻝ ﻋﻠﻰ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ 30 ‪ Examp‬ﻭﻟﻜﻦ ﳚﺐ ﺃﻥ ﺗﺪﺭﺱ‬
                         ‫ﺍﻟﺘﺮﻛﻴﺒﺔ ﺍﻟﺘﺎﻟﻴﺔ ﺣﱴ ﺗﺘﻤﻜﻦ ﻣﻦ ﻓﻬﻢ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺟﻴﺪﺍﹰ‬


                                             ‫31‬
                                        ‫ﻣﻼﺣﻈﺔ:‬
        ‫ﻋﻨﺪ ﺇﻧﺸﺎﺀ ﺃﻭ ﻓﺘﺢ ﺍﻟـ ‪ Keys‬ﺍﺳﺘﺨﺪﻡ‬
‫‪RegOpenKeyEx‬‬      ‫ﺃﻭ‬       ‫‪RegCreateKeyEx‬‬

                                      ‫ﻭﻻﺗﺴﺨﺪﻡ‬
   ‫‪RegOpenKey‬‬          ‫ﻭ‬     ‫‪RegCreateKey‬‬

‫ﻭﺫﻟﻚ ﺣﱴ ﺗﺘﻤﻜﻦ ﻣﻦ ﺍﺳﺘﺨﺪﺍﻡ ﺑﻌﺾ ﺍﻟﺪﻭﺍﻝ ﺍﻷﺧﺮﻯ.‬




   ‫41‬
                        ‫‪SECURITY_ATTRIBUTES‬‬                                ‫ﺍﻟﺘﺮﻛﻴﺒﺔ‬
                                                     ‫ﺗﺘﻜﻮﻥ ﻫﺬﻩ ﺍﻟﺘﺮﻛﻴﺒﺔ ﻣﻦ :‬
               ‫‪Long‬‬     ‫ﻣﻦ ﻧﻮﻉ‬                      ‫‪nLength‬‬

               ‫‪Long‬‬     ‫ﻣﻦ ﻧﻮﻉ‬        ‫‪lpSecurityDescriptor‬‬

               ‫‪Long‬‬     ‫ﻣﻦ ﻧﻮﻉ‬              ‫‪bInheritHandle‬‬



                                                  ‫ﺍﻟﻌﻨﺼﺮ ‪: nLength‬‬
‫ﻳﻮﺿﻊ ﺑﻪ ﺣﺠﻢ ﻫﺬﻩ ﺍﻟﺘﺮﻛﻴﺒﺔ ﺑﺎﻟﺒﺎﻳﺖ، ﻭﳚﺐ ﻋﻠﻴﻚ ﻭﺿﻊ ﺣﺠﻢ ﻫﺬﻩ‬
                ‫‪. Len‬‬     ‫ﺍﻟﺘﺮﻛﻴﺒﺔ ﰲ ﻫﺬﺍ ﺍﳌﺘﻐﲑ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ‬
                                    ‫ﺍﻟﻌﻨﺼﺮ ‪: lpSecurityDescriptor‬‬
   ‫ﻳﺸﲑ ﺇﱃ ﺻﻔﺔ ﺍﻷﻣﺎﻥ ﺍﻟﱵ ﻳﺘﺤﻜﻢ ‪‬ﺎ ﺍﻟـ ‪ Object‬ﺍﻟﺬﻱ ﻳﺘﺤﻜﻢ‬
                                                    ‫ﲟﺸﺎﺭﻛﺘﻪ.‬
 ‫ﻭﺇﻥ ﻛﺎﻥ ‪ NULL‬ﻓﺈﻥ ﺍﻟﺪﺍﻟﺔ ﻗﺪ ﺗﻌﲔ ﺍﻷﻣﻦ ﺍﻷﺳﺎﺳﻲ ) ‪( Default‬‬
                                     ‫ﻟﻠﱪﻧﺎﻣﺞ ﺍﳌﺴﺘﺪﻋﻲ ﻟﻠﺪﺍﻟﺔ.‬
        ‫‪Long‬‬            ‫ﻣﻦ ﻧﻮﻉ‬             ‫‪bInheritHandle‬‬        ‫ﺍﻟﻌﻨﺼﺮ‬
  ‫ﲢﺪﺩ ﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟـ ‪ Handle‬ﺍﳌﺮﺟﻊ ﻣﻮﺭﻭﺙ ﻋﻨﺪ ﺇﻧﺸﺎﺀ ﺍﳌﻌﺎﳉﺔ‬
   ‫ﺍﳉﺪﻳﺪﺓ ﺃﻡ ﻻ ﻓﺈﺫﺍ ﻛﺎﻥ ‪ TRUE‬ﻓﺈﻥ ﺍﳌﻌﺎﳉﺔ ﺍﳉﺪﻳﺪﺓ ﺗﻮﺭﺙ ﺍﻟـ‬
                                                    ‫‪.Handle‬‬


                           ‫30 ‪Examp‬‬               ‫ﺭﺍﺟﻊ ﺍﳌﺜﺎﻝ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ:‬




                                      ‫51‬
                                            ‫ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺍﺑﻌﺔ: ‪RegDeleteKey‬‬
    ‫ﻭﲨﻴﻊ ﳏﺘﻮﻳﺎﺗﻪ.‬   ‫‪key‬‬   ‫ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﲤﺴﺢ ﺍﻟـ‬   ‫‪Windows 9x‬‬     ‫ﰲ ﻧﻈﺎﻡ ﺍﻟﺘﺸﻐﻴﻞ‬
 ‫ﺃﻣﺎ ﰲ ‪ Widnows NT‬ﻓﺈﻥ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻻﳝﻜﻦ ﺃﻥ ﲤﺴﺢ ﺍﻟـ ‪ key‬ﺍﳌﻮﺟﻮﺩ ﺑﻪ ﻣﻔﺎﺗﻴﺢ ﻓﺮﻋﻴﺔ‬
                                       ‫ﺇﺫ ﻋﻠﻴﻚ ﻣﺴﺢ ﺍﻟـ ‪ keys‬ﺍﻟﺪﺍﺧﻠﻴﺔ ﰒ ﺍﳋﺎﺭﺟﻴﺔ.‬


                                               ‫ﻭﺗﺴﺘﻘﺒﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣﻌﺎﻣﻼﻥ ﳘﺎ:‬
‫ﳛﻮﻱ ﺍﻟـ ‪ handle‬ﳌﻔﺘﺎﺡ ﻣﻔﺘﻮﺡ‬         ‫‪Long‬‬        ‫ﻣﻦ ﻧﻮﻉ‬          ‫‪hKey‬‬

                                                               ‫ﻣﺴﺒﻘﺎﹰ‬
      ‫ﺍﺳﻢ ﺍﳌﻔﺘﺎﺡ ﺍﳌﺮﺍﺩ ﺣﺬﻓﻪ.‬       ‫‪String‬‬      ‫ﻣﻦ ﻧﻮﻉ‬      ‫‪lpSubKey‬‬



                                                                        ‫ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺟﻌﺔ:‬
                    ‫‪ERROR_SUCCESS‬‬              ‫ﺇﺫﺍ ﳒﺤﺖ ﺍﻟﺪﺍﻟﺔ ﻓﺈ‪‬ﺎ ﺗﺮﺟﻊ ﻗﻴﻤﺔ‬


                                   ‫40 ‪Examp‬‬       ‫ﻭﺭﺍﺟﻊ ﺍﳌﺜﺎﻝ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ‬


                                   ‫‪keys‬‬   ‫ﻫﺬﻩ ﺃﺭﺑﻌﺔ ﺩﻭﺍﻝ ﻋﻠﻰ ﺇﻧﺸﺎﺀ ﻭﻓﺘﺢ ﻭﺇﻏﻼﻕ ﺍﻟـ‬
       ‫ﻭﻟﻜﻦ ﳝﻜﻨﻨﺎ ﺃﻥ ﻧﻀﻊ ﻗﻴﻢ ﺃﻱ ) ‪ ( Values‬ﰲ ﺗﻠﻚ ﺍﳌﻔﺎﺗﻴﺢ ﺍﻟﱵ ﰎ ﻓﺘﺤﻬﺎ ﺃﻭ ﺇﻧﺸﺎﺀﻫﺎ‬
                                                        ‫ﻛﻴﻒ ﳝﻜﻦ ﺫﻟﻚ ؟ ﺇﻟﻴﻚ ﺑﺎﻟﺘﺎﱄ.‬




                                     ‫61‬
                 ‫ﺍﻟﺒﺎﺏ ﺍﻟﺜﺎﱐ: ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟـ ‪Values‬‬

                          ‫ﺍﻟﺪﻭﺍﻝ ﺍﻟﱵ ﺗﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟـ ‪ values‬ﻭﺍﻟﱵ ﺳﻨﺸﺮﺣﻬﺎ ﻫﺎﻫﻨﺎ ﻫﻲ:‬
                                                 ‫‪RegSetValue‬‬        ‫1.‬
                                              ‫‪RegSetValueEx‬‬         ‫2.‬
                                              ‫‪RegDeleteValue‬‬        ‫3.‬



                                                                           ‫ﻣﻼﺣﻈﺎﺕ:‬
   ‫ﻭﻗﺒﻞ ﺇﻏﻼﻗﻪ ﻷﻧﻚ ﻟﻮ ﺃﻗﻔﻠﺖ ﺍﻟـ‬   ‫‪Key‬‬   ‫ﺗﺴﺘﺨﺪﻡ ﻫﺬﻩ ﺍﻟﺪﻭﺍﻝ ﺑﻌﺪ ﻓﺘﺢ ﺍﻟـ‬
                                 ‫‪ Key‬ﻓﻠﻦ ﺗﺴﺘﻄﻴﻊ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ﺇﻻ ﺇﺫﺍ ﰎ ﻓﺘﺤﻪ ﻣﺮﺓ ﺃﺧﺮﻯ.‬



                                        ‫‪RegSetValue‬‬                   ‫ﺍﻟﺪﺍﻟﺔ ﺍﳋﺎﻣﺴﺔ:‬
 ‫ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﲣﺼﺺ ﻗﻴﻤﺔ ﻟﻠﻤﻔﺘﺎﺡ ﻭﻫﻲ ﻗﻴﻤﺔ ﳚﺐ ﺃﻥ ﺗﻜﻮﻥ ‪ String‬ﻭﻻﳝﻜﻦ ﺃﻥ ﲤﻠﻚ‬
                                     ‫1.3 ‪Win‬‬   ‫ﺇﺳﻢ ﻭﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣﺘﻮﺍﻓﻘﺔ ﻣﻊ ﻧﻈﺎﻡ ﺍﻟﺘﺸﻐﻴﻞ‬


‫ﻣﱪﳎﻲ 23‪ Win‬ﻣﻦ ﺍﻷﻓﻀﻞ ﺃﻥ ﻳﺴﺘﺨﺪﻣﻮﺍ ﺍﻟﺪﺍﻟﺔ ‪ RegSetValueEx‬ﻭﺍﻟﱵ ﺗﺴﻤﺢ ﳍﻢ ﺑﺘﺨﺼﻴﺺ‬
                                    ‫ﺃﻱ ﻋﺪﺩ ﻣﻦ ﺍﻟﻘﻴﻢ ﺍﳊﺎﻣﻠﺔ ﻟﻸﲰﺎﺀ ﻭﻣﻦ ﺃﻱ ﻧﻮﻉ ﳑﻜﻦ.‬
                                                 ‫ﻭﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﺢ ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻟﺪﺍﻟﺘﲔ:‬




                                       ‫71‬
                                                   ‫ﺗﺴﺘﻘﺒﻞ 5 ﻣﻌﺎﻣﻼﺕ:‬   ‫‪RegSetValue‬‬    ‫ﺍﻟﺪﺍﻟﺔ‬
                        ‫ﻣﻔﺘﻮﺡ ﺣﺎﻟﻴﺎﹰ.‬   ‫‪key‬‬    ‫ﳛﻤﻞ ﺍﻟـ ‪ handle‬ﻟـ‬              ‫‪hKey‬‬

              ‫ﻋﻨﻮﺍﻥ ﺍﳌﻔﺘﺎﺡ ﺍﻟﻔﺮﻋﻲ ﺍﳌﺮﺍﺩ ﲣﺰﻳﻦ ﺍﻟـ ‪ value‬ﺑﺪﺍﺧﻠﻪ.‬          ‫‪lpSubKey‬‬

‫ﻓﺈﻥ ﺍﻟـ ‪ value‬ﺗﻀﺎﻑ‬    ‫‪vbNullString‬‬      ‫ﻭﺇﺫﺍ ﻛﺎﻥ ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﻳﺴﺎﻭﻱ‬
                                 ‫ﺇﱃ ﺍﻟـ ‪ key‬ﺍﳌﺸﺎﺭ ﺇﻟﻴﻪ ﺑـ ‪. hKey‬‬
                             ‫‪REG_SZ‬‬       ‫ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ‬             ‫‪dwType‬‬

           ‫‪RegSetValueEx‬‬         ‫ﻭﻟﺘﺨﺰﻳﻦ ﺃﻧﻮﺍﻉ ﺃﺧﺮﻯ ﺍﺳﺘﺨﺪﻡ ﺍﻟﺪﺍﻟﺔ‬
                         ‫‪value‬‬   ‫ﳛﺘﻮﻱ ﻋﻠﻰ ﺍﻟﻨﺺ ﺍﳌﺮﺍﺩ ﲣﺼﻴﺼﻪ ﻟـ‬               ‫‪lpData‬‬

‫ﺑﺎﻟﺒﺎﻳﺖ ﻣﻊ ﻣﺮﺍﻋﺎﺓ ﺃﻧﻪ ﻻ ﻳﺘﻢ ﺣﺴﺎﺏ ﺣﺮﻑ‬      ‫‪lpData‬‬      ‫ﳛﺘﻮﻱ ﻋﻠﻰ ﻃﻮﻝ‬          ‫‪cbData‬‬

    ‫‪‬ﺎﻳﺔ ﺍﻟﺴﻠﺴﺔ ﺍﳊﺮﻓﻴﺔ. ﻭﺗﺴﺘﺨﺪﻡ ﺍﻟﺪﺍﻟﺔ )(‪ Len‬ﳌﻌﺮﻓﺔ ﻃﻮﻝ ﺍﻟﻨﺺ.‬


      ‫‪ERROR_SUCCESS‬‬              ‫ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺟﻌﺔ: ﺇﺫﺍ ﳒﺤﺖ ﺍﻟﺪﺍﻟﺔ ﻓﺈ‪‬ﺎ ﺗﺮﺟﻊ ﺍﻟﻘﻴﻤﺔ :‬


                     ‫ﺇﺫﺍ ﻛﺎﻥ ﺍ‪‬ﻠﺪ ﻏﲑ ﻣﻮﺟﻮﺩ ﻓﺈﻥ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺗﻨﺸﺌﻪ.‬       ‫1.‬      ‫ﻣﻼﺣﻈﺎﺕ:‬
                        ‫2. ﻃﻮﻝ ﺍﻟـ ‪ Value‬ﳏﺪﺩ ﻋﻠﻰ ﺣﺴﺐ ﺍﻟﺬﺍﻛﺮﺓ.‬


                                              ‫81‬
‫ﳚﺐ ﻋﻠﻴﻚ ﺃﻥ ﻻ ﲣﺰﻥ ﺍﻟﺒﻴﺎﻧﺎﺕ ﺍﻟﱵ ﻫﻲ ﺃﻃﻮﻝ ﻣﻦ 8402 ﺑﺎﻳﺖ ﰲ‬        ‫3.‬
‫ﺍﻟـ ‪ Regsitrt‬ﺇﺫ ﺃﻥ ﺫﻟﻚ ﻳﻘﻠﻞ ﻣﻦ ﺳﺮﻋﺔ ﺍﳉﻬﺎﺯ ﻭﺍﳊﻞ ﻫﻮ ﺃﻥ ﺗﻘﻮﻡ‬
             ‫ﲝﻔﻈﻬﺎ ﰲ ﻣﻠﻔﺎﺕ ﻭﲣﺰﻥ ﺃﲰﺎﺀﻫﺎ ﰲ ﺍﻟـ ‪.Registry‬‬



                     ‫ﻳﻮﺿﺢ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ.‬    ‫50 ‪Examp‬‬   ‫ﻭﺍﳌﺜﺎﻝ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ‬




                                    ‫91‬
                                 ‫‪:RegSetValueEx‬‬                            ‫ﺍﻟﺪﺍﻟﺔ ﺍﻟﺴﺎﺩﺳﺔ:‬
‫ﻣﻔﺘﻮﺡ ﺣﺎﻟﻴﺎﹰ، ﻭﻛﺬﻟﻚ‬   ‫‪key‬‬    ‫ﲣﺰﻥ ﺑﻴﺎﻧﺎﺕ )‪ (Data‬ﰲ ﺣﻘﻞ ﺍﻟﻘﻴﻤﺔ )‪ (Value Field‬ﻟـ‬
                              ‫ﳝﻜﻨﻬﺎ ﲣﺼﻴﺺ ﻣﻌﻠﻮﻣﺎﺕ ﺇﺿﺎﻓﻴﺔ ﻋﻦ ﺍﻟـ ‪ Values‬ﻟـ ‪ key‬ﳏﺪﺩ.‬
                                                          ‫ﺗﺴﺘﻘﺒﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺍﳌﻌﺎﻣﻼﺕ ﺍﻟﺘﺎﻟﻴﺔ:‬
                                   ‫ﺍﻟـ ‪ handle‬ﻟـ‪ key‬ﻣﻔﺘﻮﺡ ﻣﺴﺒﻘﺎﹰ.‬            ‫‪:hKey‬‬
  ‫ﻫﻮ ﻋﺒﺎﺭﺓ ﻋﻦ ﻧﺺ ﳛﻤﻞ ﺍﺳﻢ ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺍﺩ ﺗﻐﻴﲑﻫﺎ ﻭﺇﻥ ﱂ ﺗﻜﻦ‬             ‫‪:lpValueName‬‬
      ‫ﻣﻮﺟﻮﺩﺓ ﻓﺈﻥ ﺍﻟﺪﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺈﻧﺸﺎﺀﻫﺎ ﻓﺈﺫﺍ ﻛﺎﻧﺖ ﻫﺬﻩ ﺍﻟﻘﻴﻤﺔ‬
‫‪REG_SZ‬‬    ‫‪ vbNullString‬ﻭﻛﺎﻧﺖ ﻗﻴﻤﺔ ﺍﳌﻌﺎﻣﻞ ‪ dwType‬ﻫﻲ‬
                 ‫‪RegSetValue‬‬        ‫ﻓﺈﻥ ﺍﻟﺪﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺎﻟﻌﻤﻞ ﻛـ‬
                      ‫ﻫﻮ ﻣﺘﻐﲑ ﳏﺠﻮﺯ ﻭﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﺻﻔﺮﺍﹰ.‬                   ‫‪:Reserved‬‬
 ‫ﳛﺪﺩ ﻧﻮﻉ ﺍﳌﻌﻠﻮﻣﺎﺕ ﺍﻟﱵ ﺳﺘﺨﺰﻥ ﰲ ﺍﻟـ ‪ value‬ﻭﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ‬                      ‫‪:dwType‬‬
                       ‫ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻭﺍﺣﺪﺍﹰ ﻣﻦ ﺍﻟﻘﻴﻢ ﺍﻟﺘﺎﻟﻴﺔ:‬
                             ‫ﻗﻴﻢ ﺛﻨﺎﺋﻴﺔ‬     ‫‪REG_BINARY‬‬
                      ‫ﺭﻗﻢ ﻣﻦ 23 ﺑﺖ‬          ‫‪REG_DWORD‬‬
‫ﺭﻗﻢ ﻣﻦ 23 ﺑﺖ‬      ‫‪REG_DWORD_LITTLE_ENDIAN‬‬
      ‫ﺭﻗﻢ ﻣﻦ 23 ﺑﺖ‬       ‫‪REG_DWORD_BIG_ENDIAN‬‬
‫ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﲢﻮﻱ ﻋﻠﻰ ﻣﺘﻐﲑﺍﺕ‬                ‫‪REG_EXPAND_SZ‬‬
                 ‫ﺗﺪﻝ ﻋﻠﻰ ﻣﺮﺍﺟﻊ ﻣﺜﻞ "%‪"%PATH‬‬
               ‫‪Unicode‬‬   ‫ﺭﺍﺑﻂ ﺑﺮﻣﻮﺯ‬            ‫‪REG_LINK‬‬

 ‫ﻣﺼﻔﻮﻓﺔ ﲢﺘﻮﻱ ﻋﻠﻰ ‪ Strings‬ﻣﻨﺘﻬﻴﺔ‬            ‫‪REG_MULTI_SZ‬‬

                               ‫ﲝﺮﻓﲔ ﻹ‪‬ﺎﺀ ﺍﻟﺴﻠﺴﻠﺔ.‬
           ‫ﻗﻴﻤﺔ ﻣﻦ ﻧﻮﻉ ﻏﲑ ﻣﻌﺮﻭﻓﺔ‬              ‫‪REG_NONE‬‬

‫ﻗﺎﺋﻤﺔ ﳌﺮﺍﺟﻊ ﺍﻷﻭﺍﻣﺮ‬             ‫‪REG_RESOURCE_LIST‬‬

      ‫ﺍﻟﱵ ﺗﺼﺪﺭ ﻣﻦ ﺍﳊﺎﺳﻮﺏ ﺇﱃ ﺍﻷﺟﻬﺰﺓ ﺍﳋﺎﺭﺟﻴﺔ.‬
‫‪Unicode‬‬   ‫ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻭﻫﻲ ﺗﻜﻮﻥ ﻣﻦ ﻧﻮﻉ‬              ‫‪REG_SZ‬‬

          ‫ﺃﻭ ﻣﻦ ﻧﻮﻉ ‪ Ansi‬ﻭﺫﻟﻚ ﺣﺴﺐ ﺍﺳﺘﻌﻤﺎﻟﻚ.‬
‫ﻳﺆﺷﺮ ﳌﺘﻐﲑ ﳛﺘﻮﻱ ﻋﻠﻰ ﺍﻟﺒﻴﺎﻧﺎﺕ ﺍﻟﱵ ﺳﺘﺨﺰﻥ ﰲ ﺍﺳﻢ ﺍﻟﻘﻴﻤﺔ ﺍﶈﺪﺩ ﻭﻫﻮ‬                ‫‪:lpData‬‬
           ‫ﻳﻜﻮﻥ ﻣﻦ ﺃﻱ ﻧﻮﻉ ﺣﺴﺐ ﻣﺎﺣﺪﺩﻧﺎ ﻟﻪ ﰲ ﺍﳌﻌﺎﻣﻞ ‪.dwType‬‬



                                              ‫02‬
    ‫ﻣﻊ ﻣﻼﺣﻈﺔ ﻫﺎﻣﺔ ﺟﺪﺍﹰ : ﳚﺐ ﺃﻥ ﻳﺒﻌﺖ ﻫﺬﺍ ﺍﳌﻌﺎﻣﻞ ﺑﺎﻟﻘﻴﻤﺔ‬
‫ﺇﺫ ﺑﺪﻭﻥ ﻫﺬﻩ‬   ‫)‪ByVal(lpData‬‬   ‫ﻭﻟﻴﺲ ﺑﺎﳌﺮﺟﻊ ﺃﻱ ﺑﺎﺳﺘﺨﺪﺍﻡ‬
   ‫ﺍﻟﻄﺮﻳﻘﺔ ﻟﻦ ﲣﺰﻥ ﺍﻟﺒﻴﺎﻧﺎﺕ ﺻﺤﻴﺤﺔ ﻭﺳﻨﺮﻯ ﺃ‪‬ﺎ ﺳﺘﻈﻬﺮ ﻋﻠﻰ‬
     ‫ﻭﻋﻨﺪ ﺍﺳﺘﺨﺪﺍﻡ ‪ ByVal‬ﺗﻈﻬﺮ ﺍﻟﺒﻴﺎﻧﺎﺕ‬   ‫‪Garbage‬‬   ‫ﺷﻜﻞ‬
                                               ‫ﺻﺤﻴﺤﺔ‬
  ‫ﻃﻮﻝ ﺍﳌﻌﻠﻮﻣﺎﺕ ﺍﳌﺮﺍﺩ ﻣﺒﻌﻮﺛﺔ ﰲ ‪ lpData‬ﺑﺎﻟﺒﺎﻳﺖ ﻭﺇﻥ ﻛﺎﻧﺖ ﺍﻟﺒﻴﺎﻧﺎﺕ‬        ‫‪:cbData‬‬
                 ‫ﻣﻦ ﻧﻮﻉ ‪ REG_SZ‬ﺃﻭ ‪ REG_EXPAND_SZ‬ﺃﻭ‬
    ‫ﳚﺐ ﺃﻥ ﳛﺘﻮﻱ ﺍﻟﻄﻮﻝ ﻋﻠﻰ ﺍﳊﺮﻑ ﺍﳌﻨﺘﻬﻲ ﺑﻪ‬      ‫‪REG_MULT_SZ‬‬

                                                ‫ﺍﻟﺴﻠﺴﺔ ﺍﳊﺮﻓﻴﺔ.‬
                                                                  ‫ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺟﻌﺔ:‬
        ‫ﺇﺫﺍ ﳒﺤﺖ ﻓﺘﺮﺟﻊ ‪ ERROR_SUCCESS‬ﻭ ﺇﻻ ﻓﻘﻴﻤﺔ ﻏﲑﻫﺎ.‬


 ‫ﻻﺗﻘﻮﻡ ﺑﺘﺨﺰﻳﻦ ﺍﳌﻠﻔﺎﺕ ﻭﺍﻷﻳﻘﻮﻧﺎﺕ ﻭ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺘﻨﻔﻴﺬﻳﺔ ﰲ ﺍﻟـ‬          ‫ﻣﻼﺣﻈﺔ:‬
    ‫‪ Registry‬ﺣﱴ ﻻﻳﺘﻢ ﺇﻧﻘﺎﺹ ﺳﺮﻋﺔ ﺍﳉﻬﺎﺯ ﻭﻗﻢ ﺑﺘﺨﺰﻳﻨﻬﺎ ﰲ‬
                            ‫ﻣﻠﻔﺎﺕ ﺧﺎﺭﺝ ﺍﻟـ ‪.Registry‬‬
   ‫ﺃﻣﺎ ﳓﻦ ﺍﻟـﻬﺎﻛﺮ ﺍﳌﻌﻜﻮﻛﲔ ﻓﻨﻘﻮﻡ ﺑﺘﺨﺰﻳﻦ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺘﻨﻔﻴﺬﻳﺔ‬
   ‫ﺍﻟﻀﺎﺭﺓ ﻭ ﺍﻟﻔﲑﻭﺳﺎﺕ ﻫﻨﺎﻙ ﻟﺼﻐﺮ ﺣﺠﻤﻬﺎ ﺇﺫ ﻻﻳﺘﻌﺪﻯ ﺍﳌﻠﻒ‬
‫ﻛﻴﻠﻮ ﺑﺎﻳﺖ ﻭﺍﺣﺪ ﻓﻘﻂ ﻭﺃﻧﺼﺤﻜﻢ ﺑﺎﻟﺘﺤﻮﻝ ﺇﱃ ﻟﻐﺔ ﺍﻷﲰﺒﻠﻲ 23‬
       ‫ﺑﺖ ﺇﺫ ﺃﻧﲏ ﺃﺳﺘﻌﻤﻞ ﺍﳌﺘﺮﺟﻢ ‪ MASM‬ﻭﳏﺮﺭ ﺍﻟﻨﺼﻮﺹ‬
 ‫‪ RadAsm‬ﻭﻫﻲ ﻟﻐﺔ ﺃﻓﻀﻞ ﻣﻦ ﺍﻟـ ‪ Visual Basic‬ﻭﻟﻜﻨﲏ ﻻ‬
‫ﺃﻧﻘﺺ ﻣﻦ ﻫﺬﻩ ﺍﻟﻠﻐﺔ ﺇﺫ ﺃﻣﻀﻴﺖ ﻣﻌﻬﺎ ﺳﻨﻮﺍﺕ ﻻ ﻳﻔﺘﺢ ﺑﺮﻧﺎﻣﺞ ﰲ‬
‫ﺟﻬﺎﺯﻱ ﺇﻻ ﻫﺬﻩ ﺍﻟﻠﻐﺔ ‪ Visual Basic‬ﻭﻋﻤﻠﺖ ‪‬ﺎ ﺑﺮﺍﻣﺞ ﻋﺪﻳﺪﺓ‬
  ‫ﻭﺗﺘﺒﻌﻮﺍ ﻣﻮﻗﻊ ‪ vb4arab‬ﻭﺃﻧﺎ ﻭﺻﺪﻳﻘﻲ ﺍﳌﻌﻜﻮﻙ ﺳﻨﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ‬
 ‫ﺻﻔﺤﺔ ﺷﺨﺼﻴﺔ ﺧﺎﺻﺔ ﺑﻨﺎ ﺳﺄﻧﺸﺮ ﺍﲰﻬﺎ ﰲ ﻫﺬﺍ ﺍﳌﻮﻗﻊ ﻭﺳﺄﺿﻊ‬
   ‫ﰲ ﻫﺬﻩ ﺍﻟﺼﻔﺤﺔ ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﺍﻟﻜﻮﺩﺍﺕ ﺍﻟﺮﺍﺋﻌﺔ ﺍﻟﱵ ﱂ ﺃﺭﻯ ﳍﺎ‬
                                     ‫ﻣﺜﻴﻞ ﻋﻠﻰ ﺍﻹﻧﺘﺮﻧﺖ.‬
              ‫‪RegSetValueEx‬‬      ‫ﺍﳌﺜﺎﻝ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ 60 ‪ Examp‬ﻳﻮﺿﺢ ﺍﻟﺪﺍﻟﺔ‬



                                        ‫12‬
                                               ‫ﺍﻟﺪﺍﻟﺔ ﺍﻟﺴﺎﺑﻌﺔ: ‪RegDeleteVaue‬‬
                                  ‫‪Registry‬‬   ‫ﺗﺴﺘﺨﺪﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﳌﺴﺢ ﻗﻴﻤﺔ ﻣﻦ ﺍﻟـ‬
                                                       ‫ﻭﺗﺴﺘﻘﺒﻞ ﺍﳌﻌﺎﻣﻼﺕ ﺍﻟﺘﺎﻟﻴﺔ:‬


                      ‫ﳛﻤﻞ ‪ handle‬ﻟـ ‪ key‬ﻣﻔﺘﻮﺡ ﺣﺎﻟﻴﺎﹰ.‬                    ‫‪: hKey‬‬
‫‪vbNullString‬‬   ‫ﳛﻤﻞ ﺍﺳﻢ ﺍﻟـ ‪ Value‬ﺍﳌﺮﺍﺩ ﺣﺬﻓﻪ ﻭﺇﺫﺍ ﻛﺎﻧﺖ‬            ‫‪:lpValueName‬‬
         ‫ﻓﺈ‪‬ﺎ ﺗﺰﻳﻞ ﺍﻟـ ﻗﻴﻤﺔ ﺍﻟﱵ ﰎ ﻭﺿﻌﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ‬
                                          ‫‪RegSetValue‬‬


                                                          ‫ﺍﻟﻘﻴﻤﺔ ﺍﳌﺮﺟﻌﺔ ﻣﻦ ﺍﻟﺪﺍﻟﺔ:‬
 ‫‪ERROR_SUCCESS‬‬           ‫ﺗﺮﺟﻊ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺇﺫﺍ ﳒﺤﺖ ﺍﻟﻘﻴﻤﺔ‬
                  ‫ﻳﻮﺿﺢ ﺍﻟﺪﻭﺍﻝ ﺍﻟﺜﻼﺛﺔ ﺍﻟﺴﺎﺑﻘﺔ‬   ‫70 ‪Examp‬‬      ‫ﺍﳌﺜﺎﻝ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍ‪‬ﻠﺪ ﺍﳌﺴﻤﻰ‬




         ‫ﺍﻧﺘﻬﻰ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ ﻭﺗﺮﻗﺒﻮﺍ ﺍﻟﻜﺘﺎﺏ ﺍﻟﺬﻱ ﻳﺸﺮﺡ ﻛﻞ ﻫﺬﻩ ﺍﻟﺪﻭﺍﻝ ﺷﺮﺡ ﻭﺍﻓﻴﺎﹰ ﺟﺪﺍﹰ.‬
                               ‫ﻭﺳﺄﺑﺪﺃ ﰲ ﺫﻟﻚ ﺍﻟﻜﺘﺎﺏ ﻋﻨﺪﻣﺎ ﺃﻛﻤﻞ ﻣﺸﺮﻭﻉ ﺍﻟﺘﺨﺮﺝ ﺍﳊﺎﱄ.‬



                           ‫0‪Syntax Error 0x‬‬         ‫ﻛﺘﺒﻪ :‬
                           ‫ﻭﺍﻟﺴﻼﻡ ﻋﻠﻴﻜﻢ ﻭﺭﲪﺔ ﺍﷲ ﻭﺑﺮﻛﺎﺗﻪ‬




                                         ‫22‬

				
DOCUMENT INFO
Shared By:
Stats:
views:80
posted:1/18/2011
language:Arabic
pages:24
Description: كتاب التعامل مع مسجل النظام في نظام تشغيل ويندوز Registry