internal static uint RegOpenCurrentUser(uint samDesired, out SafeRegistryHandle resultKey)
 {
     return UnsafeNclNativeMethods.RegistryHelper.RegOpenCurrentUser(samDesired, out resultKey);
 }
Exemplo n.º 2
0
 internal static extern int RegSetValueEx(SafeRegistryHandle hKey, String lpValueName,
                                          int Reserved, RegistryValueKind dwType, ref long lpData, int cbData);
Exemplo n.º 3
0
 private static string ReadRegistry(bool is64, IntPtr root, string path, string valueName)
     {
     string result = null;
     using (SafeRegistryHandle hkeyRootNativeHandle = new SafeRegistryHandle(root, false))
         {
         using (RegistryKey hkeyRoot = RegistryKey.FromHandle(hkeyRootNativeHandle, is64 ? RegistryView.Registry64 : RegistryView.Registry32))
             {
             using (RegistryKey key = hkeyRoot.OpenSubKey(path))
                 {
                 result = key?.GetValue(valueName) as string;
                 }
             }
         }
     return result;
     }
Exemplo n.º 4
0
 internal static extern unsafe int RegEnumKeyEx(SafeRegistryHandle hKey, int dwIndex,
                                                char[] lpName, ref int lpcbName, int[] lpReserved,
                                                [Out] StringBuilder lpClass, int[] lpcbClass,
                                                long[] lpftLastWriteTime);
Exemplo n.º 5
0
 internal static extern int RegOpenKeyEx(SafeRegistryHandle hKey, String lpSubKey,
                                         int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
Exemplo n.º 6
0
        private static void StopRegistryMonitor() {
            // Cleanup allocated handles
            s_stopMonitoring = true;

            if (s_regHandle != null) {
                s_regHandle.Close();
                s_regHandle = null;
            }

            if (s_waitHandle != null) {
                s_waitHandle.Unregister(s_notifyEvent);
                s_waitHandle = null;
            }

            if (s_notifyEvent != null) {
                s_notifyEvent.Close();
                s_notifyEvent = null;
            }

            Trace(TAG_DEBUG_VERBOSE, "Registry monitoring stopped."); 
        }
Exemplo n.º 7
0
 internal static extern int RegDeleteKeyEx(
     SafeRegistryHandle hKey,
     string lpSubKey,
     int samDesired,
     int Reserved);
Exemplo n.º 8
0
 private static extern int RegQueryValueEx_(SafeRegistryHandle hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpValueName, IntPtr lpReserved, out uint lpType, IntPtr lpData, ref int lpcbData);
 private PerformanceDataRegistryKey(SafeRegistryHandle hkey)
 {
     _hkey = hkey;
 }
Exemplo n.º 10
0
 static extern int NtOpenKeyEx(
     out SafeRegistryHandle KeyHandle,
     GenericAccessRights DesiredAccess,
     [In] ObjectAttributes ObjectAttributes,
     int OpenOptions
     );
Exemplo n.º 11
0
 private static extern uint RegOpenKeyEx_(SafeRegistryHandle hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, uint ulOptions, uint samDesired, out SafeRegistryHandle result);
Exemplo n.º 12
0
        private static void QueryValueExImpl(SafeRegistryHandle handle, string valueName, out int valueKind, out object value)
        {
            valueName = valueName ?? ""; // it looks like RegQueryValueEx can fail with null, use empty string instead
            valueKind = 0;
            int dwRet;

            byte[] data   = new byte[128];
            uint   length = (uint)data.Length;

            // query the size first, reading the data as we query...
            dwRet = RegQueryValueEx(handle, valueName, IntPtr.Zero, out valueKind, data, ref length);
            while (dwRet == ERROR_MORE_DATA)
            {
                data   = new byte[data.Length * 2];
                length = (uint)data.Length;
                dwRet  = RegQueryValueEx(handle, valueName, IntPtr.Zero, out valueKind, data, ref length);
            }

            if (dwRet == PythonExceptions._OSError.ERROR_FILE_NOT_FOUND)
            {
                throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, PythonExceptions._OSError.ERROR_FILE_NOT_FOUND, "The system cannot find the file specified", null, PythonExceptions._OSError.ERROR_FILE_NOT_FOUND);
            }
            if (dwRet != ERROR_SUCCESS)
            {
                throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, dwRet);
            }

            // convert the result into a Python object

            switch (valueKind)
            {
            case REG_MULTI_SZ:
                PythonList list     = new PythonList();
                int        curIndex = 0;
                while (curIndex < length)
                {
                    for (int dataIndex = curIndex; dataIndex < length; dataIndex += 2)
                    {
                        if (data[dataIndex] == 0 && data[dataIndex + 1] == 0)
                        {
                            // got a full string
                            list.Add(ExtractString(data, curIndex, dataIndex));
                            curIndex = dataIndex + 2;

                            if (curIndex + 2 <= length && data[curIndex] == 0 && data[curIndex + 1] == 0)
                            {
                                // double null terminated
                                curIndex = data.Length;
                                break;
                            }
                        }
                    }

                    if (curIndex != data.Length)
                    {
                        // not null terminated
                        list.Add(ExtractString(data, curIndex, data.Length));
                    }
                }
                value = list;
                break;

            case REG_BINARY:
                var tight_fit_data = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    tight_fit_data[i] = data[i];
                }
                value = length == 0 ? null : Bytes.Make(tight_fit_data);
                break;

            case REG_EXPAND_SZ:
            case REG_SZ:
                if (length >= 2 && data[length - 1] == 0 && data[length - 2] == 0)
                {
                    value = ExtractString(data, 0, (int)length - 2);
                }
                else
                {
                    value = ExtractString(data, 0, (int)length);
                }
                break;

            case REG_DWORD:
                if (BitConverter.IsLittleEndian)
                {
                    value = (uint)((data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]);
                }
                else
                {
                    value = (uint)((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
                }
                break;

            default:
                value = null;
                break;
            }
        }
Exemplo n.º 13
0
 internal static extern int RegQueryReflectionKey(
     SafeRegistryHandle hBase,
     out bool bIsReflectionDisabled);
Exemplo n.º 14
0
 internal static extern int RegEnableReflectionKey(
     SafeRegistryHandle hKey);
 internal static extern uint RegOpenCurrentUser(uint samDesired, out SafeRegistryHandle resultKey);
        public static PerformanceDataRegistryKey OpenLocal()
        {
            var key = new SafeRegistryHandle(new IntPtr(PerformanceData), ownsHandle: true);

            return(new PerformanceDataRegistryKey(key));
        }
Exemplo n.º 17
0
 internal extern static int RegOpenKeyEx(IntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
Exemplo n.º 18
0
 private RegistryKey(SafeRegistryHandle hkey)
 {
     _hkey = hkey;
 }
 public static RegistryKey FromHandle(SafeRegistryHandle handle);
Exemplo n.º 20
0
 internal RegistrySecurity(SafeRegistryHandle hKey, string name, AccessControlSections includeSections)
     : base(true, ResourceType.RegistryKey, (SafeHandle)hKey, includeSections, new NativeObjectSecurity.ExceptionFromErrorCode(RegistrySecurity._HandleErrorCode), (object)null)
 {
     new RegistryPermission(RegistryPermissionAccess.NoAccess, AccessControlActions.View, name).Demand();
 }
Exemplo n.º 21
0
 internal static extern int RegDeleteValue(SafeRegistryHandle hKey, String lpValueName);
Exemplo n.º 22
0
 internal static partial int RegOpenKeyEx(
     IntPtr hKey,
     string?lpSubKey,
     int ulOptions,
     int samDesired,
     out SafeRegistryHandle hkResult);
Exemplo n.º 23
0
 internal static extern unsafe int RegEnumValue(SafeRegistryHandle hKey, int dwIndex,
                                                char[] lpValueName, ref int lpcbValueName,
                                                IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData,
                                                int[] lpcbData);
Exemplo n.º 24
0
 public IRegistryKey FromHandle(
     SafeRegistryHandle handle
     )
 {
     return(new RegistryKeyWrap(RegistryKey.FromHandle(handle)));
 }
Exemplo n.º 25
0
 internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, String lpValueName,
                                            int[] lpReserved, ref int lpType, [Out] char[] lpData,
                                            ref int lpcbData);
 public static RegistryKey FromHandle(SafeRegistryHandle handle)
 {
     return(FromHandle(handle, RegistryView.Default));
 }
Exemplo n.º 27
0
 public static extern int RegNotifyChangeKeyValue(
     SafeRegistryHandle key,
     bool watchSubtree,
     RegistryNotifyFilter notifyFilter,
     SafeWaitHandle eventHandle,
     bool asynchronous);
 /// <summary>
 /// Creates a RegistryKey. This key is bound to hkey, if writable is <b>false</b> then no write operations will be allowed.
 /// </summary>
 private RegistryKey(SafeRegistryHandle hkey, bool writable, RegistryView view) :
     this(hkey, writable, false, false, false, view)
 {
 }
Exemplo n.º 29
0
 internal uint RegOpenKeyEx(string subKey, uint ulOptions, uint samDesired, out SafeRegistryHandle resultSubKey)
 {
     return UnsafeNclNativeMethods.RegistryHelper.RegOpenKeyEx(this, subKey, ulOptions, samDesired, out resultSubKey);
 }
Exemplo n.º 30
0
 public RegistryKey FromHandle(SafeRegistryHandle handle)
 {
     throw new NotImplementedException();
 }
 internal static extern uint RegOpenKeyEx(SafeRegistryHandle key, string subKey, uint ulOptions, uint samDesired, out SafeRegistryHandle resultSubKey);
Exemplo n.º 32
0
 private static extern int RegSetValue(SafeRegistryHandle handle, string value, int regType, string sb, int sizeIgnored);
 internal static extern uint RegQueryValueEx(SafeRegistryHandle key, string valueName, IntPtr reserved, out uint type, [Out] byte[] data, [In][Out] ref uint size);
Exemplo n.º 34
0
 private static extern int RegQueryValueEx(SafeRegistryHandle handle, string valueName, int[] reserved, IntPtr regType, [Out] byte[] value, ref int size);
Exemplo n.º 35
0
 internal extern static int RegNotifyChangeKeyValue(SafeRegistryHandle hKey, bool watchSubTree, uint notifyFilter, SafeWaitHandle regEvent, bool async);
Exemplo n.º 36
0
 internal RegistrySecurity(SafeRegistryHandle hKey, string name, AccessControlSections includeSections)
     : base(true, ResourceType.RegistryKey, hKey, includeSections, _HandleErrorCode, null)
 {
 }
Exemplo n.º 37
0
        private static void MonitorRegistryForOneChange() {
            // Close the open reg handle
            if (s_regHandle != null) {
                s_regHandle.Close();
                s_regHandle = null;
            }

            // Open the reg key
            int result = NativeMethods.RegOpenKeyEx(NativeMethods.HKEY_LOCAL_MACHINE, s_listenKeyName, 0, NativeMethods.KEY_READ, out s_regHandle);
            if (result != 0) {
                StopRegistryMonitor();
                return;
            }

            // Listen for changes.
            result = NativeMethods.RegNotifyChangeKeyValue(
                    s_regHandle, 
                    true, 
                    NativeMethods.REG_NOTIFY_CHANGE_NAME | NativeMethods.REG_NOTIFY_CHANGE_LAST_SET,
                    s_notifyEvent.SafeWaitHandle,
                    true);

            if (result != 0) {
                StopRegistryMonitor();
            }
        }
 /// <summary>
 /// The constructor
 /// </summary>
 /// <param name="safeRegistryHandle"></param>
 public SafeRegistryHandleWrap(SafeRegistryHandle safeRegistryHandle)
 {
     SafeRegistryHandleInstance = safeRegistryHandle;
 }
 public static RegistryKey FromHandle(SafeRegistryHandle handle, RegistryView view);
Exemplo n.º 40
0
 internal static extern int RegDeleteKey(
     SafeRegistryHandle hKey,
     string lpSubKey);