如果应用程序有应用程序清单,如何以编程方式获取C#?

时间:2014-08-28 11:53:33

标签: c# embed manifest

我已经看到如何使用此引用How can I embed an application manifest into an application using VS2008?

向应用程序(控制台应用程序或Windows窗体应用程序)添加清单

herehere了解将应用程序的清单文件嵌入PE的方法

您可以按照以下步骤向C#应用程序添加清单:

  1. 在解决方案资源管理器中右键单击您的项目
  2. 从上下文菜单中选择“添加新项目”。
  3. 从显示的对话框中的选项列表中选择“Application Manifest File”。
  4. 现在,

    如果应用程序具有应用程序清单,我希望以编程方式获取,例如,从requestedExecutionLevel节点获取level和uiAccess值。

    <security>
      <applicationRequestMinimum>
        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
        <defaultAssemblyRequest permissionSetReference="Custom" />
      </applicationRequestMinimum>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    
      </requestedPrivileges>
    </security>
    

    该解决方案的两种替代方案,

    1)在应用程序的源代码中添加代码。

    2)将代码添加到使用某些应用程序的公共库中。

    完整源代码示例应用程序的最终解决方案?

    恕我直言,用于最小化学习曲线的更好样本是具有完整源代码和良好模式的真实应用程序。

1 个答案:

答案 0 :(得分:0)

我认为已经找到了解决问题的方法。

请记住,这可能不是最佳解决方案,我相信如果您对该主题进行更多研究,您会找到更好的解决方案。

string exeFileData = File.ReadAllText(@"path\file.exe");
string dllFileData = File.ReadAllText(@"path\file.dll");

if (exeFileData.Contains("manifestVersion"))
{
    Console.WriteLine("Exe contains a manifest");
}

if (dllFileData.Contains("manifestVersion"))
{
    Console.WriteLine("Dll contains a manifest");
}

这可能是您能想到的最简单的解决方案。

只需从 exe 或 dll 文件中读取所有文本,因为应用程序清单是明文且 xml 格式包含在 exe 或 dll 文件中,因此我们只需检查添加的清单中是否存在某些字符串,在我的示例中,ma​​nifestVersion 属性包含在 exe 或 dll 文件中。

就像我说的,这肯定不是最好的解决方案,但我发现它对我有用。