.net – Why does a .NET File.Delete() fail with UAC and requireAdministrator=True

managednetuacwindows-vista

This is a driving me nuts. I have searched all over StackOverflow and read all about UAC. But I'm still running into a problem.

Using VS 2008, I have a simple program that does nothing but this:

File.Delete("c:\windows\fonts\whatever.ttf")

The EXE has a proper manifest with requireAdministrator=True. When compiled, the app icon receives the shield icon. And when I launch the application, logged in as either an Admin or Standad user, I receive the "Do you want the following program to make changes…" confirmation dialog. Additionally, I use a code signing cert on the EXE.

When running the app, I get the following behaviors:

When I run the application when logged in as an Administrator, the file is deleted.

However, when logged in as a Standard user, I get a UAC prompt and enter in an Admin password, but I get a "file access is denied" error when the delete executes.

Can someone explain this to me? I thought that the requiresAdministrator=True in the manifest elevates the process. But I still can't delete a system file.

Thanks.

Best Answer

It does elevate the process, but if the file has access controls dictating that only members of the Administrator's group can modify or delete it and the "Standard" user is not a member of the Administrator's group, then he still cannot modify the file.