Esempio n. 1
0
 internal void GetValue(
     string lpSubKey,
     string lpValue,
     Win32Api.RegRestrictionFlags dwFlags,
     /*ref UInt32*/ IntPtr pdwType,
     IntPtr pvData,
     /*ref UInt32*/ IntPtr pcbData)
 {
     ApplyReadOperation(lpSubKey, new KeySecurity(Win32Api.KeySecurity.KEY_QUERY_VALUE),
                        keyImpl =>
                        TryAlterData(lpSubKey, lpValue, keyImpl, pdwType,
                                     new Data(pvData, pcbData, Data.CountIn.Bytes),
                                     (newpdwType, dst) =>
                                     Win32Exception.CatchError(
                                         () => keyImpl.TryGetValue(lpValue, dwFlags, newpdwType,
                                                                   dst.Ptr, dst.PCount))));
 }
Esempio n. 2
0
 public void QueryValue(
     string lpSubKey,
     string lpValueName,
     IntPtr lpReserved,
     IntPtr lpType,
     IntPtr lpData,
     IntPtr lpcbData)
 {
     // This function is implemented explicitely and separately from
     // GetValue because RegQueryValue and RegGetValue behavior in regard
     // to strings and null characters differ.
     ApplyReadOperation(lpSubKey, new KeySecurity(Win32Api.KeySecurity.KEY_QUERY_VALUE),
                        keyImpl =>
                        TryAlterData(lpSubKey, lpValueName, keyImpl, lpType,
                                     new Data(lpData, lpcbData, Data.CountIn.Bytes),
                                     (newpdwType, dst) =>
                                     Win32Exception.CatchError(
                                         () => keyImpl.TryQueryValue(lpValueName, lpReserved, newpdwType,
                                                                     dst.Ptr, dst.PCount))));
 }
Esempio n. 3
0
        public void EnumValue(
            uint dwIndex,
            IntPtr lpValueName,
            /*ref UInt32*/ IntPtr lpcchValueName,
            IntPtr lpReserved,
            /*ref Win32Api.RegValueType*/ IntPtr lpType,
            IntPtr lpData,
            /*ref UInt32*/ IntPtr lpcbData)
        {
            // TODO: this function does not take into account the intersection
            // of value names between windows regisry key and offreg key, this is
            // to be done in the next version

            // It does not matter if the current key is open in windows registry or in offreg
            // we need to open and enumerate both them
            int cchValueName = 0;

            if (lpcchValueName != IntPtr.Zero)
            {
                cchValueName = Marshal.ReadInt32(lpcchValueName);
            }
            KeyImplOperation enumValue = keyImpl =>
                                         TryAlterData(null, null, keyImpl, lpType,
                                                      new Data(lpData, lpcbData, Data.CountIn.Bytes),
                                                      (newpdwType, dst) =>
                                                      Win32Exception.CatchError(
                                                          () =>
            {
                // EnumValue takes buffer size WITH null character
                // but returns WITHOUT, so we need to reset input
                // param to allow multiple calls to the operation
                if (lpcchValueName != IntPtr.Zero)
                {
                    Marshal.WriteInt32(lpcchValueName, cchValueName);
                }
                keyImpl.EnumValue(dwIndex, lpValueName,
                                  lpcchValueName, lpReserved, newpdwType,
                                  dst.Ptr, dst.PCount);
            }));

            foreach (KeyDisposition disposition in HIVES_REVERSE_ORDER)
            {
                bool indexHandled = false;
                TryApplyOperation(disposition, null,
                                  new KeySecurity(Win32Api.KeySecurity.KEY_QUERY_VALUE), keyImpl =>
                {
                    uint cValues = keyImpl.QueryInfo().ValuesNumber;
                    if (dwIndex < cValues)
                    {
                        enumValue(keyImpl);
                        indexHandled = true;
                    }
                    else
                    {
                        dwIndex -= cValues;
                    }
                    return(true);
                });
                if (indexHandled)
                {
                    return;
                }
            }
            throw Win32Exception.Create((int)Win32Api.Error.ERROR_NO_MORE_ITEMS);
        }