2

I am writing some tests for a build system and I ran into a problem I couldn't really solve in C#.

I need to check multiple exe and dll files if they have a application manifest.

I have seen some people solve this problem by just seeing if the User executes some program with elevated privileges like here and some solving it with C++ like here for example. However this doesn't work in my case since I am not executing these exe and dll files.

Isn't there some easy way to check if there is an application manifest attached to an exe or dll file?

TIA.

SnarkDev
  • 111
  • 7
  • Every program written in the past 15 years has a manifest. Quite unlikely that its mere presence tells you anything you need to know. As always at SO, ask about the X and not the Y. – Hans Passant Apr 19 '21 at 23:19
  • @HansPassant In my case I really need to know if its there. Since the files that I am checking were built with Borland C++ Builder. So there is no application manifest automatically added to the output file because of that I add the application manifest manually and have to write a test for it. – SnarkDev Apr 21 '21 at 05:41

1 Answers1

1

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.

However I had to come up with one in a shorter amount of time, so here is the solution I came up with.

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