Beispiel #1
0
        public bool TryOpen(KeyIdentity identity, KeySecurity samDesired, out IKeyImpl openedImpl)
        {
            WindowsKey windowsKey;
            bool       result = WindowsKey.TryOpen(identity, samDesired, out windowsKey);

            openedImpl = windowsKey;
            return(result);
        }
Beispiel #2
0
 public bool Handle(WindowsKey key)
 {
     if (!KeyIdentity.IsPredefined(key.Handle))
     {
         return Win32Exception.CheckIfFoundAndNoError(
             Win32Api.NtQueryKey(key.Handle, KeyInformationClass_, KeyInformation_, Length_,
             out ResultLength_));
     }
     // Predefined key handle values are valid only on the advapi32.dll level
     // on the ntdll.dll level we have to replace them with appropriate ntdll.dll handles
     IntPtr hNtKey = IntPtr.Zero;
     string objectName = KeyIdentity.GetSystemBasePath(key.Handle);
     Win32Api.UNICODE_STRING usObjectName = new Win32Api.UNICODE_STRING();
     usObjectName.Length = unchecked((ushort)(sizeof(char) * objectName.Length));
     usObjectName.MaximumLength = usObjectName.Length;
     using (HGlobalPtr pObjectNameBuffer = new HGlobalPtr(Marshal.StringToHGlobalUni(objectName)))
     {
         usObjectName.Buffer = pObjectNameBuffer.Ptr;
         using (HGlobalPtr pObjectName = new HGlobalPtr(Marshal.SizeOf(typeof(Win32Api.UNICODE_STRING))))
         {
             Marshal.StructureToPtr(usObjectName, pObjectName.Ptr, false);
             Win32Api.OBJECT_ATTRIBUTES oa = new Win32Api.OBJECT_ATTRIBUTES();
             oa.Length = unchecked((uint)Marshal.SizeOf(typeof(Win32Api.OBJECT_ATTRIBUTES)));
             oa.RootDirectory = IntPtr.Zero;
             oa.ObjectName = pObjectName.Ptr;
             oa.Attributes = (uint)Win32Api.ObjectAttributes.OBJ_CASE_INSENSITIVE;
             oa.SecurityDescriptor = IntPtr.Zero;
             oa.SecurityQualityOfService = IntPtr.Zero;
             using (HGlobalPtr pOA = new HGlobalPtr(Marshal.SizeOf(typeof(Win32Api.OBJECT_ATTRIBUTES))))
             {
                 Marshal.StructureToPtr(oa, pOA.Ptr, false);
                 if (!Win32Exception.CheckIfFoundAndNoError(
                     Win32Api.NtOpenKey(out hNtKey, (uint)Win32Api.KeySecurity.KEY_QUERY_VALUE, pOA.Ptr)))
                 {
                     return false;
                 }
                 try
                 {
                     return Win32Exception.CheckIfFoundAndNoError(
                         Win32Api.NtQueryKey(hNtKey, KeyInformationClass_, KeyInformation_, Length_,
                         out ResultLength_));
                 }
                 finally
                 {
                     Win32Api.NtClose(hNtKey);
                 }
             }
         }
     }
 }
Beispiel #3
0
        public static bool TryOpen(KeyIdentity identity, KeySecurity samDesired, out WindowsKey openedImpl)
        {
            if (identity.GetRegPath() == null)
            {
                // This works fine because baseKey is always one of the predefined
                // registry keys, so its handle does not need to be duplicated
                // or closed
                openedImpl = new WindowsKey(identity.BaseKey, samDesired);
                return(true);
            }
            IntPtr handle;
            int    result = Win32Api.RegOpenKeyEx(identity.BaseKey, identity.GetRegPath(), 0,
                                                  samDesired.Value | (Win32Api.KeySecurity)identity.GetWow64Mode(),
                                                  out handle);

            openedImpl = null;
            if (!Win32Exception.CheckIfFoundAndNoError(result))
            {
                return(false);
            }
            openedImpl = new WindowsKey(handle, samDesired);
            return(true);
        }
Beispiel #4
0
 public bool Handle(WindowsKey key)
 {
     return(Win32Exception.CheckIfFoundAndNoError(
                Win32Api.RegGetKeySecurity(key.Handle, securityInformation_, pSecurityDescriptor_, lpcbSecurityDescriptor_)));
 }
 public bool Handle(WindowsKey key)
 {
     return(Win32Exception.CheckIfFoundAndNoError(
                Win32Api.RegNotifyChangeKeyValue(key.Handle, watchSubtree_, notifyFilter_, hEvent_,
                                                 asynchronous_)));
 }