Question

I made a WPF application which reads/writes other processes' memory, makes a large use of registry keys, reads/writes files on disk and downloads/deploys files from a website. LOL no, it's not a trojan, don't worry :D

It has been compiled under Framework 4.5 so it will normally be compatible only with Windows Vista or later editions, and, to work properly, it will need admin rights. Now... in order to grant it all the permissions it needs in a transparent way, I found a wide range of possibilities googling around. The ones I find simpler are:

1) Inserting the following code in the manifest:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

2) Checking if the UAC is enabled and if the used has not admin rights, if it is like so, asking to the user if he wants to grant admin rights to the application. Then, if the answer is "Yes", running an elevated application process using:

ProcessStartInfo.Verb = "runas";

So... what is the best way to handle this problem?

I also have another question. My application will load an Assembly from a byte array after startup using:

Byte[] assemblyData;

using (BinaryReader reader = new BinaryReader(new FileStream(filePath, FileMode.Open)))
    assemblyData = reader.ReadBytes(Convert.ToInt32(fs.Length));

Assembly assembly = Assembly.Load(assemblyData);
MethodInfo method = assembly.EntryPoint;

if (method != null)
{
    Object instance = assembly.CreateInstance(method.Name);
    method.Invoke(o, null);
}

My question is... will the Assembly being loaded from memory in the above code snippet (another WPF application) have the same privileges of the application that loaded it? If now, how should I deal with admin rights once again?

Was it helpful?

Solution

If your application needs admin rights for most of its operation, use

<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

If you application needs admin rights for 1-2 operations that seldom happen, then launch with AsInvoker rights and elevate your application for that specific operation.

Since the assembly that you are reading is loaded into your process memory, it will have the same privilege as your application has.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top