English 中文(简体)
Why does a .NET File.Delete() fail with UAC and requireAdministrator=True?
原标题:

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:windowsfontswhatever.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.

问题回答

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.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签