private bool GetRequestedExecutionLevel(out string requestedExecutionLevel)
        {
            bool flag;

            requestedExecutionLevel = "asInvoker";
            if (((base.InputManifest == null) || string.IsNullOrEmpty(base.InputManifest.ItemSpec)) || (string.CompareOrdinal(base.InputManifest.ItemSpec, "NoManifest") == 0))
            {
                return(false);
            }
            try
            {
                using (Stream stream = File.Open(base.InputManifest.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(stream);
                    XmlNamespaceManager namespaceManager = XmlNamespaces.GetNamespaceManager(document.NameTable);
                    XmlNode             node             = (XmlElement)document.SelectSingleNode("/asmv1:assembly/asmv2:trustInfo/asmv2:security/asmv3:requestedPrivileges/asmv3:requestedExecutionLevel", namespaceManager);
                    if (node != null)
                    {
                        XmlAttribute namedItem = (XmlAttribute)node.Attributes.GetNamedItem("level");
                        if (namedItem != null)
                        {
                            requestedExecutionLevel = namedItem.Value;
                        }
                    }
                    flag = true;
                }
            }
            catch (Exception exception)
            {
                base.Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", new object[] { base.InputManifest.ItemSpec, exception.Message });
                flag = false;
            }
            return(flag);
        }
예제 #2
0
        private bool GetRequestedExecutionLevel(out string requestedExecutionLevel)
        {
            requestedExecutionLevel = Constants.UACAsInvoker;  // For backwards compatibility we assume asInvoker to begin with.

            if (InputManifest == null || String.IsNullOrEmpty(InputManifest.ItemSpec) || String.CompareOrdinal(InputManifest.ItemSpec, "NoManifest") == 0)
            {
                return(false);
            }

            try
            {
                using (Stream s = File.Open(InputManifest.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XmlDocument       document   = new XmlDocument();
                    XmlReaderSettings xrSettings = new XmlReaderSettings();
                    xrSettings.DtdProcessing = DtdProcessing.Ignore;
                    using (XmlReader xr = XmlReader.Create(s, xrSettings))
                    {
                        document.Load(xr);

                        //Create an XmlNamespaceManager for resolving namespaces.
                        XmlNamespaceManager nsmgr = XmlNamespaces.GetNamespaceManager(document.NameTable);

                        XmlNode node = (XmlElement)document.SelectSingleNode(XPaths.requestedExecutionLevelPath, nsmgr);
                        if (node != null)
                        {
                            XmlAttribute attr = (XmlAttribute)(node.Attributes.GetNamedItem("level"));
                            if (attr != null)
                            {
                                requestedExecutionLevel = attr.Value;
                            }
                        }
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", InputManifest.ItemSpec, ex.Message);
                return(false);
            }
        }