Пример #1
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);
        }
Пример #2
0
        internal static List <string> GetOffRegPaths(KeyIdentity identity)
        {
            if (!predefinedPaths_.ContainsKey((Int64)identity.BaseKey))
            {
                return(new List <string>());
            }
            List <string> result    = new List <string>();
            List <string> basePaths = predefinedPaths_[(Int64)identity.BaseKey];
            string        regPath   = identity.GetRegPath();

            foreach (string basePath in basePaths)
            {
                // offreg hive does not distinguish between 32bit and 64 bit branches for now
                // so we use path w/o Wow6432Node
                result.Add(KeyIdentity.CombinePaths(basePath, regPath));
            }
            return(result);
        }
Пример #3
0
        internal KeyIdentity(KeyIdentity parentIdentity, Win32Api.RegWow64Options wowOptions, string subKey)
        {
            // Which are the options:
            // 0. The process is either 32 or 64 bit.
            // 1. ParentIdentity is either 32 or 64 or it is too high level key so path does not yet include
            // Wow6432Node, this means "Default" flags.
            // 2. wowOptions is either 32, 64

            // It can be that subKey == null, parentIdentity uses "default" flags,
            // in this case we have to decide add Wow6432Node...
            // and because of so many places where it may appear...
            // better to make some system function do that for us.

            // Resulting wowOptions are assigned wowOptions specified in the function call
            // because as per msdn they MUST be equal to those used in previous calls for opening
            // parent keys.

            // Creating default (32 bit on 32bit OS, 64 bit on 64 bit OS) identity to get canonized path
            KeyIdentity defaultIdentity = new KeyIdentity(parentIdentity.baseKey_, CombinePaths(parentIdentity.GetRegPath(), subKey));

            baseKey_ = defaultIdentity.baseKey_; // Canonized base key
            // Taking care of Wow64 if we are on 64 bit OS after we canonized the path and base key.
            systemPathRelativeToBaseKey_ = defaultIdentity.AdjustWow64PathIfNeeded(wowOptions);
        }
Пример #4
0
 internal static string GetMainOffRegPath(KeyIdentity identity)
 {
     if (!predefinedPaths_.ContainsKey((Int64)identity.BaseKey))
     {
         // Not thrown in usual cases, may be thrown very rarely if identity.BaseKey
         // points to some specific place (may be)
         throw new FileNotFoundException();
     }
     return(KeyIdentity.CombinePaths(predefinedPaths_[(Int64)identity.BaseKey][0], identity.GetRegPath()));
 }