I have an application that can be installed anywhere. I don't want it to prompt the user when the program is in an unprotected folder. Is it possible to only show a UAC prompt when the application is in Program Files (or a similar protected folder)?
I'm using this code at the moment to check if it has write access (from this question):
public static bool HasWriteAccess(string folder) {
try {
System.Security.AccessControl.DirectorySecurity ds = Directory.GetAccessControl(folder);
return true;
}
catch(UnauthorizedAccessException) {
return false;
}
}
I know that the code cannot be run in Program.cs
or frmMain_Load
because that is after the application has started, and so won't work.