Search code examples
c#impersonationfileshare

Reading hidden share in C#


So I have a small C# app that needs to periodically check the contents of directories on multiple machines on the network. I thought I could just read \hostname\C$ as a directory path, but with the normal Directory class there doesn't seem to be a way to authenticate against the other servers so you can access the hidden share. I'm sure there's an easy way to do this that I've overlooked, but at the moment I'm a bit stumpted.


Solution

  • From http://bytes.com/forum/thread689145.html:

    All processes run in the context of a logged-in user account. If you want to open a file on another computer, your application must be running in the context of a user that has permissions to open files on that machine. You can do this with Impersonation.

    The easiest way seems to be to give the current user appropriate rights on the other machines.