protected RegistryDataKey(string fullPath, IntPtr regHandle)
        {
            ISpRegDataKey  spRegDataKey   = (ISpRegDataKey) new SpDataKey();
            SAPIErrorCodes sAPIErrorCodes = (SAPIErrorCodes)spRegDataKey.SetKey(regHandle, false);

            if (sAPIErrorCodes != 0 && sAPIErrorCodes != SAPIErrorCodes.SPERR_ALREADY_INITIALIZED)
            {
                throw new InvalidOperationException();
            }
            _sapiRegKey     = spRegDataKey;
            _sKeyId         = fullPath;
            _disposeSapiKey = true;
        }
        protected RegistryDataKey(string fullPath, SafeRegistryHandle regHandle)
        {
            ISpRegDataKey  regKey  = (ISpRegDataKey) new SpDataKey();
            SAPIErrorCodes hresult = (SAPIErrorCodes)regKey.SetKey(regHandle, false);

            regHandle?.Close();
            if ((hresult != SAPIErrorCodes.S_OK) && (hresult != SAPIErrorCodes.SPERR_ALREADY_INITIALIZED))
            {
                throw new InvalidOperationException();
            }

            _sapiRegKey     = regKey;
            _sKeyId         = fullPath;
            _disposeSapiKey = true;
        }