Say if I built a windows application that reads files from a network folder. The network folds restrict the access to only one user "fooUser". The application is installed in several machines on the network.
I need to replace the current user with "fooUser" in order to be able to access the files on the network folder by code.
You could just set up a mapped drive to the folder share that uses the 'fooUser' credentials.
Though if you have the login/password for the user you can get your code to use impersonation. As per my answer to Windows Impersonation from C# :
use the runas utility: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true
Hope this helps.
Here is a very simple impersonation scheme that will let you be anyone for a shot period (granted you have the appropriate credentials.)
This class will do all of the heavy lifting for you....
And you can use it like so;
It is very important to place the impersonator in the 'using' block, or to dispose it when you are done doing your impersonated tasks, or the system will continue to impersonate indefinitely, which will cause all kinds of problems.
You can check if this question LogonUser and delegation would help you.