3

I have seen how add manifest to a application (Console app, or Windows Form app) using this reference How can I embed an application manifest into an application using VS2008?

here and here for ways to embed my application's manifest files inside the PE

You can add a manifest to your C# application by following these steps:

  1. Right-click on your project in the Solution Explorer
  2. Select "Add New Item" from the context menu.
  3. Choose "Application Manifest File" from the list of options in the dialog box that appears.

Now,

I want get programmatically if an application has application manifest and for example get level and uiAccess values from requestedExecutionLevel node.

<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>

And two alternatives for that solution,

1) Add the code in source code of application.

2) Add the code in a common library that use some applications.

Any final solution with full source code sample application ?

IMHO, better samples for minimize learning curve are real applications with full source code and good patterns.

Community
  • 1
  • 1
Kiquenet
  • 14,494
  • 35
  • 148
  • 243

1 Answers1

0

I think have found a solution for the problem.

Keep in mind that this is probably not the best solution and I am sure that if you were to do more research on the topic you would find a better solution.

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");
}

It is probably the simplest solution that you could come up with.

Just read all the text from a exe or dll file, since the application manifest is clear text and in xml format contained in the exe or dll file, so we just have to check if some string that exists in the added manifest, in my example the manifestVersion attribute, is contained in the exe or dll file.

Like I said this is surely not the best solution but I found it working for me.

SnarkDev
  • 111
  • 7