Is there any way to trigger Vista's UAC popup only if the application tries to do certain things? For example, if I want to copy a file to an area that the normal user does not have permission, it currently just says access denied (that I can see with errno). Is there any way to pop up with UAC only if this happens or does this involve starting an entirely new instance of the application with UAC and killing off the old one, losing all of its internal state?

Most of the time my application doesn't need to do anything that requires administrative permissions but occasionally it needs to write to a few files that need them (because I can't change the location of these file due to other applications that use it and it isn't feasible to ask users to change the file permissions themselves as most of them don't even know what file permissions are).

I should mention that I'm using C and the Win32 API but any hints in other languages like C# would probably be useful so that I can get a starting point.




Please note that I'm not asking how to turn UAC off and I don't actually want to either, before anyone posts something to that extent.