Can user schmoe_j run an app that copies files to a directory that schmoe_j can't write to?
No, permissions on files are handled by the file system which is at a much lower level in the system than C# code runs as. C# code can't directly bypass file system security. If the application runs as schmoe_j it can't write to locations on disk that schmoe_j doesn't have write-access to.
One exception is if schmoe_j has backup & restore privileges, in which case he can write to anywhere on disk. Normal users don't have this privilege because it is a very dangerous privilege to grant.
There are other theoretical ways - for example, if an insecure service is on the box that can be persuaded by a standard user to write to an arbitrary place on disk. Any such cases is a security hole that should be fixed.
Depending on the class being used, usually an exception will be thrown when you don't have proper permissions to write to a directory.
As an example, according to MSDN, when calling File.Create and File.Copy, an UnauthorizedAccessException
will be thrown when the caller does not have the required permissions.
You can include an Manifest with your executable to request that the application is run with higher privileges.
I think normally the way this is handed is to use a service (or service application) which runs under elevated permissions but with a very small surface area and no GUI. The user interacts with an application running under lower permissions which would do things that user's account can do - place files in a dropoff folder, write to a database, etc. Think IIS, MMC, TrustedInstaller, etc.
The application will run under the user's rights, if the user can;t do it, the application can't do it.
HOWEVER, the application can attempt to impersonate another user, in which case it would be able to gain access to that directory. This involved the app temporarily gaining the rights of another user. this is how ASP.NET works quite often.
The up-shot is that the user would have to provide the credentials of the impersonated user.
Article demonstrating this.
Can he run the app? Yes. It will throw an UnauthorizedAccessException
when it tries to copy those files, but not before.