My application now needs to create and then write files to a temp directory that resides within its installed directory. The msi puts it in Program Files\ by default. I didn’t consider what would happen though if some poor soul runs it using a non administrative account.
Description: Access to the path 'Temp' is denied.
StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj)
at System.IO.Directory.CreateDirectory(String path)
I looked on my computer and by default any account in the users group doesn’t have write permissions for just about every folder. I guess I’m ignorant of it all because I always run all my stuff as an administrator without even thinking about it.
Anyways, is there a way to:
1: Code the directory creating/file writing so that it temporarily elevates the permissions of the program to administrator if it’s not running as an administrator (I’m using C#)
2: Configure the installer to set the directory permissions to ‘full control’ for everybody in the ‘Users’ group (using windows setup project msis)
Thanks!
Don’t do that.
You should write to per-user directories in the AppData folder. (or
Path.GetTempPath(), which is in that)Anything else will create security vulnerabilities.