Steve Kiss
Steve Kiss

Reputation: 1118

Windows Application Different Privileges from the User Running it

I realise this is a broad question, but if anyone can point me in the right direction I would appreciate it. Security is not my strong point.

I have a WPF application that generates a series of Crystal Reports and does some IO operations. All files it works on are located on a shared folder on the network, say \fs\MyFiles.

The user running the application should have Read Only access to this network folder, but the application should have Full Control over the folder.

What I am thinking is the application needs to execute under a different security Principal than the user running it. Is this possible in Windows? What should I look at in order to do this?

Upvotes: 0

Views: 51

Answers (1)

Micah Armantrout
Micah Armantrout

Reputation: 6971

This is possible say it is a network share

networkCredential theNetworkCredential = new NetworkCredential(username, password, domain);
CredentialCache theNetcache = new CredentialCache();
theNetCache.Add(@"\\computer", theNetworkCredential, "Basic", theNetworkCredential);
//then do whatever, such as getting a list of folders:
string[] theFolders = System.IO.Directory.GetDirectories("@\\computer\share");

This will cause the application to have different creds then the actual logged in user. I would suggest putting the username and password and domain encrypted in a config file

Upvotes: 2

Related Questions