(C #) How do you check if a path is a protected path on Windows that requires a height change?
We have a folder where our application will potentially read, write, and create / delete files, and while we can default to a safe location, we allow the user to select a different directory. How can we check if the selected directory is "safe"?
We would not require elevation of administrator rights at runtime, and this path will be used for subsequent launches of the application, so it is not enough for us to check if our process can currently write to this place, because it can that the application is launched with administrator rights the first times (this actually happens when the installer launches, since the installer runs at an elevated level), and if they choose a protected location, then the next time they try to launch the application, they won't have access to the directory. Potentially GB of persistent data is stored in this location, so requesting a new location and moving files is not ideal.
a source to share
Other advice about changing permissions at any time is valid, but checking the installation time is even better than not checking at all.
Since the first run will be promoted, what you probably want to do is start a separate process without the promotion to check the location, and then the original instance can continue to understand that the location will work unless / until someone changes the permissions.
a source to share