예제 #1
0
        public static Dictionary <string, string> GetMimeContentTypesFromRegistry()
        {
            RegistryPermission          regPerm = new RegistryPermission(RegistryPermissionAccess.Read, @"\\HKEY_CLASSES_ROOT");
            RegistryKey                 typeKey = Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type");
            StringBuilder               sb      = new StringBuilder();
            Dictionary <String, String> d       = new Dictionary <string, string>();

            foreach (string keyname in typeKey.GetSubKeyNames())
            {
                RegistryKey curKey = typeKey.OpenSubKey(keyname);
                if (curKey != null)
                {
                    object extension = curKey.GetValue("Extension");
                    if (extension != null)
                    {
                        d[extension.ToString()] = keyname;
                    }
                }
            }
            return(d);
        }
예제 #2
0
        public static void RegistryPermissionCallMethods()
        {
            Permissions.RegistryPermissionAccess rpa = new Permissions.RegistryPermissionAccess();
            RegistryPermission rp  = new RegistryPermission(new Permissions.PermissionState());
            RegistryPermission rp2 = new RegistryPermission(rpa, new System.Security.AccessControl.AccessControlActions(), "testpath");
            RegistryPermission rp3 = new RegistryPermission(rpa, "testpath");

            rp.AddPathList(rpa, "testpath");
            IPermission ip       = rp.Copy();
            string      path     = rp.GetPathList(rpa);
            IPermission ip2      = rp.Intersect(ip);
            bool        testbool = rp.IsSubsetOf(ip);

            testbool = rp.IsUnrestricted();
            rp.SetPathList(rpa, "testpath");
            ip2 = rp.Union(ip);
            SecurityElement se = new SecurityElement("");

            rp.FromXml(se);
            se = rp.ToXml();
        }
        public void AddPathList_Subset()
        {
            RegistryPermission ep = new RegistryPermission(PermissionState.None);

            ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachine);
            ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachineSubset);
            SecurityElement se = ep.ToXml();

            Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Create"), "AddPathList-ToXml-Create");
            Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Read"), "AddPathList-ToXml-Read");
            Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Write"), "AddPathList-ToXml-Write");

            ep = new RegistryPermission(PermissionState.None);
            ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachine);
            ep.AddPathList(RegistryPermissionAccess.Create, keyLocalMachineSubset);
            ep.AddPathList(RegistryPermissionAccess.Read, keyCurrentUser);
            se = ep.ToXml();
            Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Create"), "AddPathList-ToXml-Create");
            Assert.AreEqual(keyLocalMachine + ";" + keyCurrentUser, se.Attribute("Read"), "AddPathList-ToXml-Read");
            Assert.AreEqual(keyLocalMachine, se.Attribute("Write"), "AddPathList-ToXml-Write");
        }
예제 #4
0
        private ResourcePool CreateResourcePool()
        {
            ResourcePool.TransactionEndDelegate enddelegate = new ResourcePool.TransactionEndDelegate(this.PutEndTxConnection);
#if DEBUG
            try {
                (new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\COM3\\System.EnterpriseServices")).Assert(); // MDAC 84045
                try {
#endif
            return(new ResourcePool(enddelegate));

#if DEBUG
        }
        finally {
            RegistryPermission.RevertAssert();
        }
    }
    catch {
        throw;
    }
#endif
        }
예제 #5
0
        /// <summary>
        /// Load IE Window title from registry
        /// </summary>
        private void LoadIEWindowTitle()
        {
            RegistryKey        localUsr = null;
            RegistryKey        ours     = null;
            RegistryPermission rp       = null;

            this.ieWindowTitle = " - ";

            try
            {
                // Get read permission.
                rp = new RegistryPermission(RegistryPermissionAccess.Read,
                                            "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Internet Explorer\\Main");

                // Open the local machine key.
                localUsr = Registry.CurrentUser;
                ours     = localUsr.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Main");

                this.ieWindowTitle += ours.GetValue("Window Title");
            }
            catch (ArgumentException) {}
        }
예제 #6
0
        private static long GetNetFxSecurityRegistryValue(string regValueName, long defaultValue)
        {
            // Acquire permissions to read the one key we care about from the registry
            RegistryPermission permission = new RegistryPermission(
                RegistryPermissionAccess.Read,
                System.Security.AccessControl.AccessControlActions.View,
                _NetFxSecurityFullKeyName);

            permission.Assert();

            try
            {
                using (RegistryKey securityRegKey = Registry.LocalMachine.OpenSubKey(_NetFxSecurityKey, false))
                {
                    if (securityRegKey != null)
                    {
                        object regValue = securityRegKey.GetValue(regValueName);
                        if (regValue != null)
                        {
                            RegistryValueKind valueKind = securityRegKey.GetValueKind(regValueName);
                            if (valueKind == RegistryValueKind.DWord || valueKind == RegistryValueKind.QWord)
                            {
                                return(Convert.ToInt64(regValue, CultureInfo.InvariantCulture));
                            }
                        }
                    }
                }
            }
            catch (SecurityException)
            {
                // we could not open the key - that's fine, we can proceed with the default value
            }
            finally
            {
                RegistryPermission.RevertAssert();
            }

            return(defaultValue);
        }
예제 #7
0
        /// <summary>
        /// Determines mime type of a file first by searching the Windows Registry,
        /// and if not sucessful, calls Win32-API FindMimeFromData in urlmon.dll, finally uses its own list.
        /// </summary>
        public static string GetContentType(FileInfo fileinfo)
        {
            const string TypeUnknown = "application/octet-stream";
            string       mime        = string.Empty;

            if (fileinfo == null)
            {
                throw new NullReferenceException("fileinfo must not be null.");
            }

            try
            {
                var         dummy          = new RegistryPermission(RegistryPermissionAccess.Read, @"\\HKEY_CLASSES_ROOT");
                RegistryKey rkContentTypes = Registry.ClassesRoot.OpenSubKey(fileinfo.Extension);
                if (rkContentTypes != null)
                {
                    object key = rkContentTypes.GetValue("Content Type");
                    // there may be entries for this extension, that do not have a content type in registry
                    mime = key != null?key.ToString() : string.Empty;
                }

                if (string.IsNullOrEmpty(mime))
                {
                    mime = GetContentTypeByWinApi(fileinfo);
                }
            }
            catch
            {
                // error reading mime type from registry or using Windows API
            }

            // if no mime type found up to now, finally use our own list
            if (string.IsNullOrEmpty(mime))
            {
                mime = MimeTypes.GetMimeType(fileinfo.Name);
            }
            return(string.IsNullOrEmpty(mime) ? TypeUnknown : mime);
        }
예제 #8
0
        /// <summary>
        /// Content Type
        /// </summary>
        /// <param name="filepath">File Path</param>
        /// <returns>Content Type</returns>
        public string ContentType(string filepath)
        {
            if (string.IsNullOrWhiteSpace(filepath))
            {
                throw new ArgumentException("filepath");
            }

            var fi     = new FileInfo(filepath);
            var dotExt = fi.Extension.ToUpperInvariant();

            if (string.IsNullOrWhiteSpace(dotExt))
            {
                throw new InvalidOperationException(string.Format("Unknown extension: {0}", dotExt));
            }

            if (!types.ContainsKey(dotExt))
            {
                var regPerm = new RegistryPermission(RegistryPermissionAccess.Read, "\\\\HKEY_CLASSES_ROOT");
                using (var classesRoot = Registry.ClassesRoot)
                    using (var typeKey = classesRoot.OpenSubKey("MIME\\Database\\Content Type"))
                    {
                        foreach (var keyname in typeKey.GetSubKeyNames())
                        {
                            using (var curKey = classesRoot.OpenSubKey("MIME\\Database\\Content Type\\" + keyname))
                            {
                                var extension = curKey.GetValue("Extension");
                                if (null != extension && extension.ToString().ToUpperInvariant() == dotExt)
                                {
                                    types.Add(dotExt, keyname);
                                    break;
                                }
                            }
                        }
                    }
            }

            return(types.ContainsKey(dotExt) ? types[dotExt] : string.Empty);
        }
예제 #9
0
    //</Snippet6>
    //<Snippet9>
    // AddPathList adds access for the specified registry variables to the existing state of the permission.
    // SetPathList sets new access for the specified registry variable names to the existing state of the permission.
    // GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess.
    private static bool SetGetPathListDemo()
    {
        try
        {
            Console.WriteLine("********************************************************\n");
            //<Snippet10>
            RegistryPermission readPerm1;
            Console.WriteLine("Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
            readPerm1 = new RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            //</Snippet10>
            Console.WriteLine("Adding 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION' to the write access list, "
                              + "and \n 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0' "
                              + "to the read access list.");
            readPerm1.AddPathList(RegistryPermissionAccess.Write, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION");
            readPerm1.AddPathList(RegistryPermissionAccess.Read,
                                  "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0");
            Console.WriteLine("Read access list before SetPathList = " +
                              readPerm1.GetPathList(RegistryPermissionAccess.Read));
            Console.WriteLine("Setting read access rights to \n'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
            readPerm1.SetPathList(RegistryPermissionAccess.Read,
                                  "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            Console.WriteLine("Read access list after SetPathList = \n" +
                              readPerm1.GetPathList(RegistryPermissionAccess.Read));
            Console.WriteLine("Write access = \n" +
                              readPerm1.GetPathList(RegistryPermissionAccess.Write));
            Console.WriteLine("Write access Registry variables = \n" +
                              readPerm1.GetPathList(RegistryPermissionAccess.AllAccess));
        }
        catch (ArgumentException e)
        {
            // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
            Console.WriteLine("An ArgumentException occured as a result of using AllAccess. "
                              + "AllAccess cannot be used as a parameter in GetPathList because it represents more than one "
                              + "type of registry variable access : \n" + e);
        }

        return(true);
    }
예제 #10
0
        ///
        /// Read and return a registry value.
        static internal object ReadRegistryValue(RegistryKey baseRegistryKey, string keyName, string valueName)
        {
            object value = null;

            new RegistryPermission(RegistryPermissionAccess.Read, baseRegistryKey.Name + @"\" + keyName).Assert();
            try
            {
                RegistryKey key = baseRegistryKey.OpenSubKey(keyName);
                if (key != null)
                {
                    using ( key )
                    {
                        value = key.GetValue(valueName);
                    }
                }
            }
            finally
            {
                RegistryPermission.RevertAssert();
            }

            return(value);
        }
예제 #11
0
        public void GetPathList()
        {
            RegistryPermission ep = new RegistryPermission(PermissionState.None);

#if NET_2_0
            Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.Create), "GetPathList-Create-Empty");
            Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.Read), "GetPathList-Read-Empty");
            Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.Write), "GetPathList-Write-Empty");
#else
            Assert.IsNull(ep.GetPathList(RegistryPermissionAccess.Create), "GetPathList-Create-Empty");
            Assert.IsNull(ep.GetPathList(RegistryPermissionAccess.Read), "GetPathList-Read-Empty");
            Assert.IsNull(ep.GetPathList(RegistryPermissionAccess.Write), "GetPathList-Write-Empty");
#endif
            ep.AddPathList(RegistryPermissionAccess.Create, keyLocalMachine);
            ep.AddPathList(RegistryPermissionAccess.Create, keyCurrentUser);
            Assert.AreEqual(keyLocalMachine + ";" + keyCurrentUser, ep.GetPathList(RegistryPermissionAccess.Create), "GetPathList-Read");

            ep.AddPathList(RegistryPermissionAccess.Read, keyLocalMachine);
            Assert.AreEqual(keyLocalMachine, ep.GetPathList(RegistryPermissionAccess.Read), "GetPathList-Read");

            ep.AddPathList(RegistryPermissionAccess.Write, keyCurrentUser);
            Assert.AreEqual(keyCurrentUser, ep.GetPathList(RegistryPermissionAccess.Write), "GetPathList-Write");
        }
예제 #12
0
        private void ExtractDisallowedRegistryList()
        {
            string[]    disallowedAssemblies;
            RegistryKey featureKey;

            //Assert for read access to HKLM\Software\Microsoft\.NetFramework\Policy\APTCA
            (new RegistryPermission(RegistryPermissionAccess.Read, KILL_BIT_REGISTRY_HIVE + KILL_BIT_REGISTRY_LOCATION)).Assert();//BlessedAssert
            try
            {
                // open the key and read the value
                featureKey = Registry.LocalMachine.OpenSubKey(KILL_BIT_REGISTRY_LOCATION);
                if (featureKey != null)
                {
                    // Enumerate through all keys and populate dictionary
                    disallowedAssemblies = featureKey.GetSubKeyNames();
                    // iterate over this list and for each extract the APTCA_FLAG value and set it in the
                    // dictionary
                    foreach (string assemblyName in disallowedAssemblies)
                    {
                        featureKey = Registry.LocalMachine.OpenSubKey(KILL_BIT_REGISTRY_LOCATION + @"\" + assemblyName);
                        object keyValue = featureKey.GetValue(SUBKEY_VALUE);
                        // if there exists a value and it is 1 add to hash table
                        if ((keyValue != null) && (int)(keyValue) == 1)
                        {
                            if (!_assemblyList.Value.Contains(assemblyName))
                            {
                                _assemblyList.Value.Add(assemblyName.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim());
                            }
                        }
                    }
                }
            }
            finally
            {
                RegistryPermission.RevertAssert();
            }
        }
예제 #13
0
        public void IsSubsetOfNull()
        {
            RegistryPermission ep1 = new RegistryPermission(RegistryPermissionAccess.Read, keyLocalMachine);

            Assert.IsTrue(!ep1.IsSubsetOf(null), "IsSubsetOf(null)");
        }
예제 #14
0
 public void IntersectWithBadPermission()
 {
     RegistryPermission   ep1  = new RegistryPermission(RegistryPermissionAccess.Read, keyLocalMachine);
     FileDialogPermission fdp2 = new FileDialogPermission(PermissionState.Unrestricted);
     RegistryPermission   ep3  = (RegistryPermission)ep1.Intersect(fdp2);
 }
예제 #15
0
        public void FromXmlNull()
        {
            RegistryPermission ep = new RegistryPermission(PermissionState.None);

            ep.FromXml(null);
        }
예제 #16
0
        }// ValidateData

        internal override IPermission GetCurrentPermission()
        {
            // Change cells so we get data committed to the grid
            m_dg.CurrentCell = new DataGridCell(0, 1);
            m_dg.CurrentCell = new DataGridCell(0, 0);

            RegistryPermission perm = null;

            if (m_radUnrestricted.Checked == true)
            {
                perm = new RegistryPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new RegistryPermission(PermissionState.None);
                StringCollection scRead   = new StringCollection();
                StringCollection scWrite  = new StringCollection();
                StringCollection scCreate = new StringCollection();
                for (int i = 0; i < m_dt.Rows.Count; i++)
                {
                    // Make sure we have a registry permission to add
                    if (m_dg[i, 0] is String && ((String)m_dg[i, 0]).Length > 0)
                    {
                        // Does this path have read permissions
                        if ((bool)m_dg[i, 1])
                        {
                            scRead.Add((String)m_dg[i, 0]);
                        }
                        // Does this path have write permissions
                        if ((bool)m_dg[i, 2])
                        {
                            scWrite.Add((String)m_dg[i, 0]);
                        }
                        // Does this have append permissions
                        if ((bool)m_dg[i, 3])
                        {
                            scCreate.Add((String)m_dg[i, 0]);
                        }
                    }
                    else
                    {
                        // Make sure they didn't check any boxes and not include
                        // an empty path
                        bool fCheckedBox = false;
                        for (int j = 1; j <= 3 && !fCheckedBox; j++)
                        {
                            fCheckedBox = (bool)m_dg[i, j];
                        }

                        if (fCheckedBox)
                        {
                            MessageBox(CResourceStore.GetString("RegPerm:NeedRegName"),
                                       CResourceStore.GetString("RegPerm:NeedRegNameTitle"),
                                       MB.ICONEXCLAMATION);
                            return(null);
                        }
                    }
                }
                String sAdd = PathListFunctions.JoinStringCollection(scRead);
                if (sAdd.Length > 0)
                {
                    perm.AddPathList(RegistryPermissionAccess.Read, sAdd);
                }

                String sWrite = PathListFunctions.JoinStringCollection(scWrite);
                if (sWrite.Length > 0)
                {
                    perm.AddPathList(RegistryPermissionAccess.Write, sWrite);
                }

                String sCreate = PathListFunctions.JoinStringCollection(scCreate);
                if (sCreate.Length > 0)
                {
                    perm.AddPathList(RegistryPermissionAccess.Create, sCreate);
                }
            }
            return(perm);
        }// GetCurrentPermission
예제 #17
0
        internal static bool IsFeatureDisabled(KeyToRead key)
        {
            string regValue = null;
            bool   fResult  = false;

            switch (key)
            {
            case KeyToRead.WebBrowserDisable:
                regValue = RegistryKeys.value_WebBrowserDisallow;
                break;

            case KeyToRead.MediaAudioDisable:
                regValue = RegistryKeys.value_MediaAudioDisallow;
                break;

            case KeyToRead.MediaVideoDisable:
                regValue = RegistryKeys.value_MediaVideoDisallow;
                break;

            case KeyToRead.MediaImageDisable:
                regValue = RegistryKeys.value_MediaImageDisallow;
                break;

            case KeyToRead.MediaAudioOrVideoDisable:
                regValue = RegistryKeys.value_MediaAudioDisallow;
                break;

            case KeyToRead.ScriptInteropDisable:
                regValue = RegistryKeys.value_ScriptInteropDisallow;
                break;

            default:    // throw exception for invalid key
                throw(new System.ArgumentException(key.ToString()));
            }

            RegistryKey featureKey;
            //Assert for read access to HKLM\Software\Microsoft\Windows\Avalon
            RegistryPermission regPerm = new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\" + RegistryKeys.WPF_Features); //BlessedAssert

            regPerm.Assert();                                                                                                                       //BlessedAssert
            try
            {
                object obj      = null;
                bool   keyValue = false;
                // open the key and read the value
                featureKey = Registry.LocalMachine.OpenSubKey(RegistryKeys.WPF_Features);
                if (featureKey != null)
                {
                    // If key exists and value is 1 return true else false
                    obj      = featureKey.GetValue(regValue);
                    keyValue = obj is int && ((int)obj == 1);
                    if (keyValue)
                    {
                        fResult = true;
                    }

                    // special case for audio and video since they can be orred
                    // this is in the condition that audio is enabled since that is
                    // the path that MediaAudioVideoDisable defaults to
                    // This is purely to optimize perf on the number of calls to assert
                    // in the media or audio scenario.

                    if ((fResult == false) && (key == KeyToRead.MediaAudioOrVideoDisable))
                    {
                        regValue = RegistryKeys.value_MediaVideoDisallow;
                        // If key exists and value is 1 return true else false
                        obj      = featureKey.GetValue(regValue);
                        keyValue = obj is int && ((int)obj == 1);
                        if (keyValue)
                        {
                            fResult = true;
                        }
                    }
                }
            }
            finally
            {
                RegistryPermission.RevertAssert();
            }
            return(fResult);
        }
예제 #18
0
 public static void RegistryPermissionCallMethods()
 {
     Permissions.RegistryPermissionAccess rpa = new Permissions.RegistryPermissionAccess();
     RegistryPermission rp = new RegistryPermission(new Permissions.PermissionState());
     RegistryPermission rp2 = new RegistryPermission(rpa, new System.Security.AccessControl.AccessControlActions(), "testpath");
     RegistryPermission rp3 = new RegistryPermission(rpa, "testpath");
     rp.AddPathList(rpa, "testpath");
     IPermission ip = rp.Copy();
     string path = rp.GetPathList(rpa);
     IPermission ip2 = rp.Intersect(ip);
     bool testbool = rp.IsSubsetOf(ip);
     testbool = rp.IsUnrestricted();
     rp.SetPathList(rpa, "testpath");
     ip2 = rp.Union(ip);
     SecurityElement se = new SecurityElement("");
     rp.FromXml(se);
     se = rp.ToXml();
 }
        internal static bool IsFeatureDisabled(SafeSecurityHelper.KeyToRead key)
        {
            bool flag = false;

            switch (key)
            {
            case SafeSecurityHelper.KeyToRead.WebBrowserDisable:
            {
                string name = "WebBrowserDisallow";
                goto IL_76;
            }

            case SafeSecurityHelper.KeyToRead.MediaAudioDisable:
            {
                string name = "MediaAudioDisallow";
                goto IL_76;
            }

            case (SafeSecurityHelper.KeyToRead) 3:
            case (SafeSecurityHelper.KeyToRead) 5:
            case (SafeSecurityHelper.KeyToRead) 7:
                break;

            case SafeSecurityHelper.KeyToRead.MediaVideoDisable:
            {
                string name = "MediaVideoDisallow";
                goto IL_76;
            }

            case SafeSecurityHelper.KeyToRead.MediaAudioOrVideoDisable:
            {
                string name = "MediaAudioDisallow";
                goto IL_76;
            }

            case SafeSecurityHelper.KeyToRead.MediaImageDisable:
            {
                string name = "MediaImageDisallow";
                goto IL_76;
            }

            default:
                if (key == SafeSecurityHelper.KeyToRead.ScriptInteropDisable)
                {
                    string name = "ScriptInteropDisallow";
                    goto IL_76;
                }
                break;
            }
            throw new ArgumentException(key.ToString());
IL_76:
            RegistryPermission registryPermission = new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\.NETFramework\\Windows Presentation Foundation\\Features");

            registryPermission.Assert();
            try
            {
                RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\.NETFramework\\Windows Presentation Foundation\\Features");
                if (registryKey != null)
                {
                    string name;
                    object value = registryKey.GetValue(name);
                    bool   flag2 = value is int && (int)value == 1;
                    if (flag2)
                    {
                        flag = true;
                    }
                    if (!flag && key == SafeSecurityHelper.KeyToRead.MediaAudioOrVideoDisable)
                    {
                        name  = "MediaVideoDisallow";
                        value = registryKey.GetValue(name);
                        flag2 = (value is int && (int)value == 1);
                        if (flag2)
                        {
                            flag = true;
                        }
                    }
                }
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(flag);
        }
예제 #20
0
        /// <include file='doc\PerformanceCounterManager.uex' path='docs/doc[@for="PerformanceCounterManager.Initialize"]/*' />
        /// <devdoc>
        ///     Initializes perf com dll internal tables
        /// </devdoc>
        /// <internalonly/>
        private void Initialize()
        {
            if (FirstEntry)
            {
                lock (this) {
                    if (FirstEntry)
                    {
                        RegistryKey parentKey = null;
                        perfObjects = new Hashtable();
                        //SECREVIEW: This is being loaded by NT, it is executed
                        //                         when perfmon collects the data for all the
                        //                         registered counters.
                        RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted);
                        registryPermission.Assert();
                        try {
                            parentKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services");
                            if (parentKey == null)
                            {
                                return;
                            }

                            string[] categoryNames = parentKey.GetSubKeyNames();
                            for (int i = 0; i < categoryNames.Length; i++)
                            {
                                try {
                                    RegistryKey currentKey = parentKey.OpenSubKey(categoryNames[i] + "\\Performance");
                                    if (currentKey == null)
                                    {
                                        continue;
                                    }

                                    object systemDllName = currentKey.GetValue("Library");
                                    if (systemDllName == null || !(systemDllName is string) || String.Compare((string)systemDllName, PerformanceCounterLib.PerfShimName, true, CultureInfo.InvariantCulture) != 0)
                                    {
                                        continue;
                                    }

                                    object openEntryPoint = currentKey.GetValue("Open");
                                    if (openEntryPoint == null || !(openEntryPoint is string) || (string)openEntryPoint != PerformanceCounterLib.OpenEntryPoint)
                                    {
                                        continue;
                                    }

                                    object collectEntryPoint = currentKey.GetValue("Collect");
                                    if (collectEntryPoint == null || !(collectEntryPoint is string) || (string)collectEntryPoint != PerformanceCounterLib.CollectEntryPoint)
                                    {
                                        continue;
                                    }

                                    object closeEntryPoint = currentKey.GetValue("Close");
                                    if (closeEntryPoint == null || !(closeEntryPoint is string) || (string)closeEntryPoint != PerformanceCounterLib.CloseEntryPoint)
                                    {
                                        continue;
                                    }

                                    object counterDisabled = currentKey.GetValue("Disable Performance Counters");
                                    if (counterDisabled != null && (int)counterDisabled != 0)
                                    {
                                        continue;
                                    }

                                    object firstCounterId = currentKey.GetValue("First Counter");
                                    if (firstCounterId == null)
                                    {
                                        continue;
                                    }

                                    object lastCounterId = currentKey.GetValue("Last Counter");
                                    if (lastCounterId == null)
                                    {
                                        continue;
                                    }

                                    object firstHelpId = currentKey.GetValue("First Help");
                                    if (firstHelpId == null)
                                    {
                                        continue;
                                    }

                                    object countersData = currentKey.GetValue("Counter Types");
                                    int[]  counterTypes = null;
                                    if (countersData == null)
                                    {
                                        counterTypes = new int[0];
                                    }
                                    else
                                    {
                                        string[] counterStrs;
                                        if (countersData is string[])
                                        {
                                            counterStrs = (string[])countersData;
                                        }
                                        else if (countersData is byte[])
                                        {
                                            counterStrs = PerformanceCounterLib.GetStrings((byte[])countersData);
                                        }
                                        else
                                        {
                                            counterStrs = new string[0];
                                        }

                                        counterTypes = new int[counterStrs.Length];
                                        for (int index = 0; index < counterTypes.Length; index++)
                                        {
                                            counterTypes[index] = Int32.Parse(counterStrs[index]);
                                        }
                                    }

                                    countersData = currentKey.GetValue("Counter Names");
                                    int[]    counterNameHashCodes = null;
                                    string[] counterNames         = null;
                                    if (countersData == null)
                                    {
                                        counterNameHashCodes = new int[0];
                                        counterNames         = new string[0];
                                    }
                                    else
                                    {
                                        string[] counterStrs;
                                        if (countersData is string[])
                                        {
                                            counterStrs = (string[])countersData;
                                        }
                                        else if (countersData is byte[])
                                        {
                                            counterStrs = PerformanceCounterLib.GetStrings((byte[])countersData);
                                        }
                                        else
                                        {
                                            counterStrs = new string[0];
                                        }

                                        counterNameHashCodes = new int[counterStrs.Length];
                                        counterNames         = new string[counterStrs.Length];
                                        for (int index = 0; index < counterTypes.Length; index++)
                                        {
                                            counterNames[index]         = counterStrs[index].ToLower(CultureInfo.InvariantCulture);
                                            counterNameHashCodes[index] = counterNames[index].GetHashCode();
                                        }
                                    }

                                    if ((int)firstCounterId != -1 && (int)firstHelpId != -1)
                                    {
                                        ObjectData data = new ObjectData();
                                        data.CategoryName         = categoryNames[i].ToLower(CultureInfo.InvariantCulture);
                                        data.CategoryNameHashCode = data.CategoryName.GetHashCode();
                                        data.CounterTypes         = counterTypes;
                                        data.CounterNames         = counterNames;
                                        data.CounterNameHashCodes = counterNameHashCodes;
                                        data.FirstCounterId       = (int)firstCounterId;
                                        data.FirstHelpId          = (int)firstHelpId;
                                        perfObjects.Add((int)firstCounterId, data);
                                    }
                                }
                                catch (Exception) {
                                }
                            }
                        }
                        finally {
                            if (parentKey != null)
                            {
                                parentKey.Close();
                            }

                            RegistryPermission.RevertAssert();
                        }

                        FirstEntry = false;
                    }
                }
            }
        }
예제 #21
0
        public void EncryptRegistryDetails(string installlocation, string wsurl, string dirlocation)
        {
            RegistryPermission fwrite = new RegistryPermission(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\");

            fwrite.AddPathList(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\");

            RegistryKey OurKey = Registry.LocalMachine;             // Create OurKey set to HKEY_LOCAL_MACHINE

            OurKey = OurKey.OpenSubKey("SOFTWARE", true);           // Set it to HKEY_LOCAL_MACHINE\SOFTWARE
            OurKey.CreateSubKey("TerraScan");                       // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan
            OurKey.CreateSubKey(@"TerraScan\TerraScanApplication"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase
            OurKey = OurKey.OpenSubKey(@"TerraScan\TerraScanApplication", true);
            OurKey.SetValue("InstallLocation", installurl);
            OurKey.SetValue("WebServiceURL", webserviceurl);
            OurKey.SetValue("InstallDirectory", iisrootdirectory);
            OurKey.SetValue("MSWCFURL", mswcfurl);
            OurKey.SetValue("Version", "1.0.25.36");
            OurKey.Close();
            OurKey = null;

            RegistryKey ComponentIDKey = Registry.LocalMachine;           // Create OurKey set to HKEY_LOCAL_MACHINE

            ComponentIDKey = ComponentIDKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE
            ComponentIDKey.CreateSubKey("TerraScan");                     // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan
            ComponentIDKey.CreateSubKey(@"TerraScan\ComponentID");        // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase
            ComponentIDKey = ComponentIDKey.OpenSubKey(@"TerraScan\ComponentID", true);
            ComponentIDKey.SetValue("ComponentID", "1");
            ComponentIDKey.Close();
            ComponentIDKey = null;


            #region to be used only if necessary
            //key = ciphwrp.Key;
            //installlocationiv = ciphwrp.AsymmIV;
            //wsurliv = ciphwrp.AsymmIV;
            //dirlocationiv = ciphwrp.AsymmIV;

            //bool testciphercreate = this.createCiphers(installlocation, wsurl, dirlocation);

            //if (testciphercreate == true)
            //{
            //    try
            //    {
            //        cipherInstallLocation = ciphwrp.EncryptMessage(plainTextInstallLocation, key, out installlocationiv);
            //        cipherWSUrl = ciphwrp.EncryptMessage(plainTextWSUrl, key, out wsurliv);
            //        cipherDirLocation = ciphwrp.EncryptMessage(plainTextDirLocation, key, out dirlocationiv);
            //    }
            //    catch (System.Security.SecurityException sec)
            //    {
            //        MessageBox.Show(sec.Message);
            //    }
            //}

            //RegistryPermission fwrite = new RegistryPermission(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\");
            //fwrite.AddPathList(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\");

            //RegistryKey OurKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE
            //OurKey = OurKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE
            //OurKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan
            //OurKey.CreateSubKey(@"TerraScan\TerraScanApplication"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase
            //OurKey = OurKey.OpenSubKey(@"TerraScan\TerraScanApplication", true);
            //OurKey.SetValue("InstallLocation", cipherWSUrl);
            //OurKey.SetValue("WebServiceURL", cipherInstallLocation);
            //OurKey.SetValue("InstallDirectory", cipherDirLocation);
            //OurKey.SetValue("Version", "1.0.25.36");
            //OurKey.Close();
            //OurKey = null;

            //RegistryKey ComponentIDKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE
            //ComponentIDKey = ComponentIDKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE
            //ComponentIDKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan
            //ComponentIDKey.CreateSubKey(@"TerraScan\ComponentID"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase
            //ComponentIDKey = ComponentIDKey.OpenSubKey(@"TerraScan\ComponentID", true);
            //ComponentIDKey.SetValue("ComponentID", "1");


            //RegistryKey ClrKey = Registry.ClassesRoot; // Create OurKey set to HKEY_LOCAL_MACHINE
            //ClrKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan
            //ClrKey.CreateSubKey(@"TerraScan\TerraScanApplication");
            //ClrKey = ClrKey.OpenSubKey(@"TerraScan\TerraScanApplication", true);
            //ClrKey.SetValue("key", key);
            //ClrKey.SetValue("installlocationiv", installlocationiv);
            //ClrKey.SetValue("wsurliv", wsurliv);
            //ClrKey.SetValue("dirlocationiv", dirlocationiv);
            //ClrKey.Close();
            //ClrKey = null;
            #endregion
        }
예제 #22
0
        //Write Registry Value
        public bool RegistryWriter(string subKey, string keyName, string keyValue, RegistryValueKind valueType)
        {
            try
            {
                RegistryPermission regeditPermission = new RegistryPermission(RegistryPermissionAccess.AllAccess, System.IO.Path.Combine(Registry.CurrentUser.ToString(), System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey)));
                regeditPermission.Demand();
                RegistryKey regeditWrite = Registry.CurrentUser;
                //regeditWrite.SetAccessControl(regeditUserRuls);
                regeditWrite = regeditWrite.OpenSubKey(System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey), true);
                if (regeditWrite != null)
                {
                    if (valueType.Equals(RegistryValueKind.Binary))
                    {
                        regeditWrite.SetValue(keyName, RegeditNecessaryFunction.ToByteArray(keyValue), RegistryValueKind.Binary);
                        regeditWrite.Close();
                        return(true);
                    }
                    else if (valueType.Equals(RegistryValueKind.DWord))
                    {
                        regeditWrite.SetValue(keyName, Convert.ToInt32(keyValue), RegistryValueKind.DWord);
                        regeditWrite.Close();
                        return(true);
                    }
                    else if (valueType.Equals(RegistryValueKind.ExpandString))
                    {
                        regeditWrite.SetValue(keyName, keyValue, RegistryValueKind.ExpandString);
                        regeditWrite.Close();
                        return(true);
                    }
                    else if (valueType.Equals(RegistryValueKind.MultiString))
                    {
                        regeditWrite.SetValue(keyName, RegeditNecessaryFunction.ToStringArray(keyValue), RegistryValueKind.MultiString);
                        regeditWrite.Close();
                        return(true);
                    }
                    else if (valueType.Equals(RegistryValueKind.QWord))
                    {
                        regeditWrite.SetValue(keyName, Convert.ToInt32(keyValue), RegistryValueKind.QWord);
                        regeditWrite.Close();
                        return(true);
                    }
                    else
                    {
                        regeditWrite.SetValue(keyName, keyValue, RegistryValueKind.String);
                        regeditWrite.Close();
                        return(true);
                    }
                }
                else
                {
                    RegistryKey regKeyCrator = Registry.CurrentUser;
                    regKeyCrator = regKeyCrator.CreateSubKey(System.IO.Path.Combine(ProcestaVariables.Variables.REGISTRY_PATH, subKey), RegistryKeyPermissionCheck.Default);

                    regKeyCrator.Close();
                    RegistryWriter(subKey, keyName, keyValue, valueType);
                    return(true);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(ProcestaVariables.Variables.ERROR_MESSAGES[0, 3] + Environment.NewLine + e, ProcestaVariables.Variables.ERROR_MESSAGES[0, 0], MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
        }
예제 #23
0
        static bool CanWrite(string key)
        {
            var perm = new RegistryPermission(RegistryPermissionAccess.Write, key);

            return(perm.IsUnrestricted());
        }
예제 #24
0
        protected override void PutValuesinPage()
        {
            // Put in the text for the radio buttons
            m_radUnrestricted.Text             = CResourceStore.GetString("RegPerm:GrantUnrestrict");
            m_radGrantFollowingPermission.Text = CResourceStore.GetString("RegPerm:GrantFollowing");

            RegistryPermission perm = (RegistryPermission)m_perm;

            CheckUnrestricted(perm);

            if (!perm.IsUnrestricted())
            {
                StringCollection scReadKeys   = new StringCollection();
                StringCollection scWriteKeys  = new StringCollection();
                StringCollection scCreateKeys = new StringCollection();
                StringCollection scRWKeys     = new StringCollection();
                StringCollection scRCKeys     = new StringCollection();
                StringCollection scWCKeys     = new StringCollection();
                StringCollection scRWCKeys    = new StringCollection();

                // Get the paths the user has access to
                if (perm.GetPathList(RegistryPermissionAccess.Read) != null)
                {
                    scReadKeys.AddRange(perm.GetPathList(RegistryPermissionAccess.Read).Split(new char[] { ';' }));
                }
                if (perm.GetPathList(RegistryPermissionAccess.Write) != null)
                {
                    scWriteKeys.AddRange(perm.GetPathList(RegistryPermissionAccess.Write).Split(new char[] { ';' }));
                }
                if (perm.GetPathList(RegistryPermissionAccess.Create) != null)
                {
                    scCreateKeys.AddRange(perm.GetPathList(RegistryPermissionAccess.Create).Split(new char[] { ';' }));
                }

                // Careful with the order of these calls... make sure the final IntersectAllCollections
                // is the last function to get called. Also, make sure each of the base
                // string collections (Read, Write, and Append) all are the 1st argument in the
                // IntersectCollections call at least once, to clean up any "" that might be floating around
                scRWKeys  = PathListFunctions.CondIntersectCollections(ref scReadKeys, ref scWriteKeys, ref scCreateKeys);
                scRCKeys  = PathListFunctions.CondIntersectCollections(ref scCreateKeys, ref scReadKeys, ref scWriteKeys);
                scWCKeys  = PathListFunctions.CondIntersectCollections(ref scWriteKeys, ref scCreateKeys, ref scReadKeys);
                scRWCKeys = PathListFunctions.IntersectAllCollections(ref scReadKeys, ref scWriteKeys, ref scCreateKeys);

                // Now we have 7 different combinations we have to run through
                String[] sFilePaths = new String[] {
                    PathListFunctions.JoinStringCollection(scReadKeys),
                    PathListFunctions.JoinStringCollection(scWriteKeys),
                    PathListFunctions.JoinStringCollection(scCreateKeys),
                    PathListFunctions.JoinStringCollection(scRWKeys),
                    PathListFunctions.JoinStringCollection(scRCKeys),
                    PathListFunctions.JoinStringCollection(scWCKeys),
                    PathListFunctions.JoinStringCollection(scRWCKeys)
                };

                RegistryPermissionAccess[] fipa = new RegistryPermissionAccess[] {
                    RegistryPermissionAccess.Read,
                    RegistryPermissionAccess.Write,
                    RegistryPermissionAccess.Create,
                    RegistryPermissionAccess.Read | RegistryPermissionAccess.Write,
                    RegistryPermissionAccess.Create | RegistryPermissionAccess.Read,
                    RegistryPermissionAccess.Create | RegistryPermissionAccess.Write,
                    RegistryPermissionAccess.Read | RegistryPermissionAccess.Write | RegistryPermissionAccess.Create
                };

                for (int i = 0; i < 7; i++)
                {
                    DataRow newRow;
                    // See if we have some info for this one
                    if (sFilePaths[i].Length > 0)
                    {
                        newRow           = m_dt.NewRow();
                        newRow["Key"]    = sFilePaths[i];
                        newRow["Read"]   = (fipa[i] & RegistryPermissionAccess.Read) > 0;
                        newRow["Write"]  = (fipa[i] & RegistryPermissionAccess.Write) > 0;
                        newRow["Create"] = (fipa[i] & RegistryPermissionAccess.Create) > 0;
                        m_dt.Rows.Add(newRow);
                    }
                }
            }

            // We want at least 1 rows so it looks pretty
            while (m_dt.Rows.Count < 1)
            {
                AddEmptyRow(m_dt);
            }
        }// PutValuesinPage
예제 #25
0
 public void NullPathList()
 {
     RegistryPermission ep = new RegistryPermission(RegistryPermissionAccess.AllAccess, null);
 }
예제 #26
0
        public void CreateAccess()
        {
            RegistryPermission ep = new RegistryPermission(RegistryPermissionAccess.Create, keyLocalMachine);

            Assert.IsTrue(!ep.IsUnrestricted(), "IsUnrestricted");
        }
예제 #27
0
        IsSupportedMimeType(
            BitmapSource bitmapSource
            )
        {
            BitmapCodecInfo codecInfo     = null;
            string          imageMimeType = "";

            if (bitmapSource is BitmapFrame)
            {
                //
                // This code gets the encoder based on the decoder that was
                // used for this specific BitmapSource.
                //
                BitmapFrame bitmapFrame = bitmapSource as BitmapFrame;

                if (bitmapFrame != null && bitmapFrame.Decoder != null)
                {
                    codecInfo = bitmapFrame.Decoder.CodecInfo;
                }
            }

            if (codecInfo != null)
            {
                (new RegistryPermission(PermissionState.Unrestricted)).Assert();
                try
                {
                    imageMimeType = codecInfo.MimeTypes;
                }
                finally
                {
                    RegistryPermission.RevertAssert();
                }
            }
            int  start     = 0;
            int  comma     = imageMimeType.IndexOf(',', start);
            bool foundType = false;

            //
            // Test all strings before commas
            //
            if (comma != -1)
            {
                while (comma != -1 && !foundType)
                {
                    string subString = imageMimeType.Substring(start, comma);
                    foundType = XpsManager.SupportedImageType(new ContentType(subString));
                    start     = comma + 1;
                    comma     = imageMimeType.IndexOf(',', start);
                }
            }

            //
            // If we still have not found a supported type
            // Test the remainder of the string
            //
            if (!foundType)
            {
                foundType = XpsManager.SupportedImageType(new ContentType(imageMimeType.Substring(start)));
            }

            return(foundType);
        }
예제 #28
0
        // What if an app is locked back?  Why would we use this?
        internal static string GetLatestBuildDllDirectory(string machineName)
        {
            string      dllDir     = "";
            RegistryKey baseKey    = null;
            RegistryKey complusReg = null;

            //This property is retrieved only when creationg a new category,
            //                          the calling code already demanded PerformanceCounterPermission.
            //                          Therefore the assert below is safe.

            //This property is retrieved only when creationg a new log,
            //                          the calling code already demanded EventLogPermission.
            //                          Therefore the assert below is safe.

            RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted);

            registryPermission.Assert();

            try {
                if (machineName.Equals("."))
                {
                    return(GetLocalBuildDirectory());
                }
                else
                {
                    baseKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName);
                }
                if (baseKey == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.RegKeyMissingShort, "HKEY_LOCAL_MACHINE", machineName));
                }

                complusReg = baseKey.OpenSubKey("SOFTWARE\\Microsoft\\.NETFramework");
                if (complusReg != null)
                {
                    string installRoot = (string)complusReg.GetValue("InstallRoot");
                    if (installRoot != null && installRoot != String.Empty)
                    {
                        // the "policy" subkey contains a v{major}.{minor} subkey for each version installed.  There are also
                        // some extra subkeys like "standards" and "upgrades" we want to ignore.

                        // first we figure out what version we are...
                        string      versionPrefix = "v" + Environment.Version.Major + "." + Environment.Version.Minor;
                        RegistryKey policyKey     = complusReg.OpenSubKey("policy");

                        // This is the full version string of the install on the remote machine we want to use (for example "v2.0.50727")
                        string version = null;

                        if (policyKey != null)
                        {
                            try {
                                // First check to see if there is a version of the runtime with the same minor and major number:
                                RegistryKey bestKey = policyKey.OpenSubKey(versionPrefix);

                                if (bestKey != null)
                                {
                                    try {
                                        version = versionPrefix + "." + GetLargestBuildNumberFromKey(bestKey);
                                    } finally {
                                        bestKey.Close();
                                    }
                                }
                                else
                                {
                                    // There isn't an exact match for our version, so we will look for the largest version
                                    // installed.
                                    string[] majorVersions  = policyKey.GetSubKeyNames();
                                    int[]    largestVersion = new int[] { -1, -1, -1 };
                                    for (int i = 0; i < majorVersions.Length; i++)
                                    {
                                        string majorVersion = majorVersions[i];

                                        // If this looks like a key of the form v{something}.{something}, we should see if it's a usable build.
                                        if (majorVersion.Length > 1 && majorVersion[0] == 'v' && majorVersion.Contains("."))
                                        {
                                            int[] currentVersion = new int[] { -1, -1, -1 };

                                            string[] splitVersion = majorVersion.Substring(1).Split('.');

                                            if (splitVersion.Length != 2)
                                            {
                                                continue;
                                            }

                                            if (!Int32.TryParse(splitVersion[0], out currentVersion[0]) || !Int32.TryParse(splitVersion[1], out currentVersion[1]))
                                            {
                                                continue;
                                            }

                                            RegistryKey k = policyKey.OpenSubKey(majorVersion);
                                            if (k == null)
                                            {
                                                // We may be able to use another subkey
                                                continue;
                                            }
                                            try {
                                                currentVersion[2] = GetLargestBuildNumberFromKey(k);

                                                if (currentVersion[0] > largestVersion[0] ||
                                                    ((currentVersion[0] == largestVersion[0]) && (currentVersion[1] > largestVersion[1])))
                                                {
                                                    largestVersion = currentVersion;
                                                }
                                            } finally {
                                                k.Close();
                                            }
                                        }
                                    }

                                    version = "v" + largestVersion[0] + "." + largestVersion[1] + "." + largestVersion[2];
                                }
                            } finally {
                                policyKey.Close();
                            }

                            if (version != null && version != String.Empty)
                            {
                                StringBuilder installBuilder = new StringBuilder();
                                installBuilder.Append(installRoot);
                                if (!installRoot.EndsWith("\\", StringComparison.Ordinal))
                                {
                                    installBuilder.Append("\\");
                                }
                                installBuilder.Append(version);
                                dllDir = installBuilder.ToString();
                            }
                        }
                    }
                }
            }
            catch {
                // ignore
            }
            finally {
                if (complusReg != null)
                {
                    complusReg.Close();
                }

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

                RegistryPermission.RevertAssert();
            }

            return(dllDir);
        }
예제 #29
0
        GetEncoder(
            BitmapSource bitmapSource
            )
        {
            BitmapEncoder encoder = null;

            if (bitmapSource is BitmapFrame)
            {
                //
                // This code gets the encoder based on the decoder that was
                // used for this specific BitmapSource.
                //
                BitmapFrame     bitmapImage = bitmapSource as BitmapFrame;
                BitmapCodecInfo codecInfo   = null;

                if (bitmapImage != null && bitmapImage.Decoder != null)
                {
                    codecInfo = bitmapImage.Decoder.CodecInfo;
                }

                if (codecInfo != null)
                {
                    (new RegistryPermission(PermissionState.Unrestricted)).Assert();
                    try
                    {
                        encoder = BitmapEncoder.Create(codecInfo.ContainerFormat);
                    }
                    finally
                    {
                        RegistryPermission.RevertAssert();
                    }

                    // Avoid GIF encoder which does not save transparency well
                    if (!(encoder is JpegBitmapEncoder ||
                          encoder is PngBitmapEncoder ||
                          encoder is TiffBitmapEncoder ||
                          encoder is WmpBitmapEncoder)
                        )
                    {
                        encoder = null;
                    }
                }
            }

            //
            // The code above assumes that the BitmapSource is actually
            // a BitmapImage.  If it is not then we assume Png and use
            // that encoder.
            //
            if (encoder == null)
            {
                if (Microsoft.Internal.AlphaFlattener.Utility.NeedPremultiplyAlpha(bitmapSource))
                {
                    encoder = new WmpBitmapEncoder();
                }
                else
                {
                    encoder = new PngBitmapEncoder();
                }
            }

            return(encoder);
        }
예제 #30
0
        public void GetPathListAllAccess()
        {
            RegistryPermission ep = new RegistryPermission(PermissionState.None);

            ep.GetPathList(RegistryPermissionAccess.AllAccess);
        }
예제 #31
0
 internal CRegPermDialog(RegistryPermission perm)
 {
     this.Text      = CResourceStore.GetString("RegPerm:PermName");
     m_PermControls = new CRegPermControls(perm, this);
     Init();
 } // CRegPermDialog(RegistryPermission)