Question

I have a windows C# application which require administrator privileges. I created an app.manifest modifying it adding

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

When I run it directly from my pc everything is ok, the OS prompt me the UAC and everything work fine. Now, if I write all files into a CD (or iso image), some commands doesn't run with administrative privileges, causing errors. In particular Directory.Delete, Directory.Copy (with recoursive parameter) don't work.

I also tried to wrap the default Delete method doing something like:

[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
public static void delete(string source, bool recursive)
{
    if (Directory.Exists(source))
    {
        Directory.Delete(source, recursive);
    }
}

But I get a "Request for principal permission failed." error.

Is there other I am missing? Why it should be different if running on a directory in my pc or running from cd?

Thanks, Fabio

No correct solution

OTHER TIPS

There is something called CAS (Code Access Security) in .NET. The CLR handles your program differently when it is from another source (so Local Intranet, Internet and Local Disk are handled differently)

When you are loading from CD, the settings would revert to a mode with less privileges.

You can find more on CAS here on MSDN.

You can request privileges by adding and configuring the app.manifest file.

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